Skip to content

Commit e86e870

Browse files
authored
feat(java): deserialize oneof (#492)
1 parent ee9c021 commit e86e870

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.github/actions/restore-artifacts/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ runs:
3232

3333
# JavaScript utils
3434
- name: client-javascript-utils-client-common
35-
if: ${{ inputs.type == 'all' || inputs.type == 'js_utils' }}
35+
if: ${{ (inputs.javascript == 'true' && inputs.type == 'all') || inputs.type == 'js_utils' }}
3636
uses: actions/download-artifact@v3
3737
with:
3838
name: client-javascript-utils-client-common
3939
path: clients/algoliasearch-client-javascript/packages/client-common/
4040

4141
- name: client-javascript-utils-requester-browser-xhr
42-
if: ${{ inputs.type == 'all' || inputs.type == 'js_utils' }}
42+
if: ${{ (inputs.javascript == 'true' && inputs.type == 'all') || inputs.type == 'js_utils' }}
4343
uses: actions/download-artifact@v3
4444
with:
4545
name: client-javascript-utils-requester-browser-xhr
4646
path: clients/algoliasearch-client-javascript/packages/requester-browser-xhr/
4747

4848
- name: client-javascript-utils-requester-node-http
49-
if: ${{ inputs.type == 'all' || inputs.type == 'js_utils' }}
49+
if: ${{ (inputs.javascript == 'true' && inputs.type == 'all') || inputs.type == 'js_utils' }}
5050
uses: actions/download-artifact@v3
5151
with:
5252
name: client-javascript-utils-requester-node-http

clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/JSON.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ public static <T> T deserialize(String body, Type returnType) {
113113
}
114114
}
115115
}
116+
117+
public static <T> T tryDeserialize(JsonReader reader, Type returnType) {
118+
try {
119+
return gson.fromJson(reader, returnType);
120+
} catch (JsonParseException e) {
121+
return null;
122+
}
123+
}
116124
}
117125

118126
/** Gson TypeAdapter for Byte Array type */

templates/java/oneof_interface.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public abstract class {{classname}} implements CompoundType {
3131
@Override
3232
public {{classname}} read(final JsonReader jsonReader)
3333
throws IOException {
34+
{{#vendorExtensions.x-is-one-of-list}}
35+
{{{type}}} {{#lambda.lowercase}}{{name}}{{/lambda.lowercase}} = JSON.tryDeserialize(jsonReader, new TypeToken<{{{type}}}>() {}.getType());
36+
if({{#lambda.lowercase}}{{name}}{{/lambda.lowercase}} != null) {
37+
return {{classname}}.of{{name}}({{#lambda.lowercase}}{{name}}{{/lambda.lowercase}});
38+
}
39+
{{/vendorExtensions.x-is-one-of-list}}
3440
return null;
3541
}
3642
}

0 commit comments

Comments
 (0)