|
6 | 6 | import com.algolia.exceptions.AlgoliaRuntimeException;
|
7 | 7 | import com.fasterxml.jackson.annotation.*;
|
8 | 8 | import com.fasterxml.jackson.core.*;
|
| 9 | +import com.fasterxml.jackson.core.type.TypeReference; |
9 | 10 | import com.fasterxml.jackson.databind.*;
|
10 | 11 | import com.fasterxml.jackson.databind.annotation.*;
|
11 | 12 | import java.io.IOException;
|
| 13 | +import java.util.Map; |
12 | 14 | import java.util.logging.Logger;
|
13 | 15 |
|
14 | 16 | /** AuthInput */
|
15 | 17 | @JsonDeserialize(using = AuthInput.Deserializer.class)
|
16 | 18 | public interface AuthInput {
|
| 19 | + // AuthInput as Map<String, String> wrapper. |
| 20 | + static AuthInput of(Map<String, String> value) { |
| 21 | + return new MapOfStringStringWrapper(value); |
| 22 | + } |
| 23 | + |
| 24 | + // AuthInput as Map<String, String> wrapper. |
| 25 | + @JsonSerialize(using = MapOfStringStringWrapper.Serializer.class) |
| 26 | + class MapOfStringStringWrapper implements AuthInput { |
| 27 | + |
| 28 | + private final Map<String, String> value; |
| 29 | + |
| 30 | + MapOfStringStringWrapper(Map<String, String> value) { |
| 31 | + this.value = value; |
| 32 | + } |
| 33 | + |
| 34 | + public Map<String, String> getValue() { |
| 35 | + return value; |
| 36 | + } |
| 37 | + |
| 38 | + static class Serializer extends JsonSerializer<MapOfStringStringWrapper> { |
| 39 | + |
| 40 | + @Override |
| 41 | + public void serialize(MapOfStringStringWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException { |
| 42 | + gen.writeObject(value.getValue()); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + |
17 | 47 | class Deserializer extends JsonDeserializer<AuthInput> {
|
18 | 48 |
|
19 | 49 | private static final Logger LOGGER = Logger.getLogger(Deserializer.class.getName());
|
@@ -77,6 +107,16 @@ public AuthInput deserialize(JsonParser jp, DeserializationContext ctxt) throws
|
77 | 107 | LOGGER.finest("Failed to deserialize oneOf AuthAlgoliaInsights (error: " + e.getMessage() + ") (type: AuthAlgoliaInsights)");
|
78 | 108 | }
|
79 | 109 | }
|
| 110 | + // deserialize Map<String, String> |
| 111 | + if (tree.isObject()) { |
| 112 | + try (JsonParser parser = tree.traverse(jp.getCodec())) { |
| 113 | + Map<String, String> value = parser.readValueAs(new TypeReference<Map<String, String>>() {}); |
| 114 | + return new AuthInput.MapOfStringStringWrapper(value); |
| 115 | + } catch (Exception e) { |
| 116 | + // deserialization failed, continue |
| 117 | + LOGGER.finest("Failed to deserialize oneOf Map<String, String> (error: " + e.getMessage() + ") (type: Map<String, String>)"); |
| 118 | + } |
| 119 | + } |
80 | 120 | throw new AlgoliaRuntimeException(String.format("Failed to deserialize json element: %s", tree));
|
81 | 121 | }
|
82 | 122 |
|
|
0 commit comments