Skip to content

Commit

Permalink
Issue-88: fixed param serialisation in case field is a reserved name -
Browse files Browse the repository at this point in the history
…#88

Signed-off-by: Philipp Etschel <[email protected]>
  • Loading branch information
etschelp committed Nov 18, 2023
1 parent ae155fa commit dc44b5b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<jackson.databind.version>2.15.2</jackson.databind.version>
<junit.jupiter.api.version>5.10.0</junit.jupiter.api.version>
<kotlin.version>1.9.0</kotlin.version>
<lombok.version>1.18.28</lombok.version>
<lombok.version>1.18.30</lombok.version>
<lombok.maven.plugin.version>1.18.20.0</lombok.maven.plugin.version>
<okhttp.version>4.11.0</okhttp.version>
<pmd.version>6.55.0</pmd.version>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/hyperledger/aries/api/AcaPyRequestFilter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022 - for information on the respective copyright owner
* Copyright (c) 2020-2023 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/acapy-java-client
*
Expand Down Expand Up @@ -49,7 +49,7 @@ default HttpUrl.Builder buildParams(@NonNull HttpUrl.Builder b) {
value = ((Boolean) o).toString().toLowerCase(Locale.US);
}
if (value != null) {
b.addQueryParameter(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES.translateName(f), value);
b.addQueryParameter(translateFieldName(f), value);
}
}
} catch (IllegalAccessException e) {
Expand All @@ -58,4 +58,12 @@ default HttpUrl.Builder buildParams(@NonNull HttpUrl.Builder b) {
});
return b;
}

private static String translateFieldName(Field field) {
SerializedName sn = field.getAnnotation(SerializedName.class);
if (sn != null) {
return sn.value();
}
return FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES.translateName(field);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* Copyright (c) 2020-2022 - for information on the respective copyright owner
* Copyright (c) 2020-2023 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/acapy-java-client
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.aries.api.connection;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -18,5 +19,6 @@ public class CreateInvitationParams implements AcaPyRequestFilter {
private String alias;
private Boolean autoAccept;
private Boolean multiUse;
@SerializedName("public")
private Boolean isPublic;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022 - for information on the respective copyright owner
* Copyright (c) 2020-2023 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/acapy-java-client
*
Expand Down Expand Up @@ -40,7 +40,7 @@ public HttpUrl.Builder buildParams(@NonNull HttpUrl.Builder b) {
if (StringUtils.isNotEmpty(extraQuery)) {
b.addQueryParameter("extra_query", extraQuery);
}
if (referent != null && referent.size() > 0) {
if (referent != null && !referent.isEmpty()) {
StringBuilder sb = new StringBuilder();
Iterator<String> it = referent.stream().iterator();
while (it.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022 - for information on the respective copyright owner
* Copyright (c) 2020-2023 - for information on the respective copyright owner
* see the NOTICE file and/or the repository at
* https://github.com/hyperledger-labs/acapy-java-client
*
Expand Down Expand Up @@ -55,6 +55,13 @@ void testListWalletDid() {
Assertions.assertEquals(url + "?key_type=bls12381g2", f.buildParams(b).toString());
}

@Test
void testAnnotatedBoolean() {
HttpUrl.Builder b = Objects.requireNonNull(base).newBuilder();
AnnotatedBoolean ab = AnnotatedBoolean.builder().isPublic(Boolean.TRUE).build();
Assertions.assertEquals(url + "?public=true", ab.buildParams(b).toString());
}

@Test
void testEmptyString() {
HttpUrl.Builder b = Objects.requireNonNull(base).newBuilder();
Expand All @@ -79,4 +86,10 @@ private enum AnnotatedDummyEnum {
@SerializedName("value_2")
VALUE2
}

@Builder
private static final class AnnotatedBoolean implements AcaPyRequestFilter {
@SerializedName("public")
private Boolean isPublic;
}
}

0 comments on commit dc44b5b

Please sign in to comment.