|
| 1 | +// This file is generated, manual changes will be lost - read more on |
| 2 | +// https://github.com/algolia/api-clients-automation. |
| 3 | + |
| 4 | +package com.algolia.model.predict; |
| 5 | + |
| 6 | +import com.algolia.utils.CompoundType; |
| 7 | +import com.fasterxml.jackson.annotation.*; |
| 8 | +import com.fasterxml.jackson.core.*; |
| 9 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 10 | +import com.fasterxml.jackson.databind.*; |
| 11 | +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| 12 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| 13 | +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; |
| 14 | +import com.fasterxml.jackson.databind.ser.std.StdSerializer; |
| 15 | +import java.io.IOException; |
| 16 | + |
| 17 | +/** Affinities */ |
| 18 | +@JsonDeserialize(using = Affinities.AffinitiesDeserializer.class) |
| 19 | +@JsonSerialize(using = Affinities.AffinitiesSerializer.class) |
| 20 | +public abstract class Affinities implements CompoundType { |
| 21 | + |
| 22 | + public static Affinities of(AffinitiesSuccess inside) { |
| 23 | + return new AffinitiesAffinitiesSuccess(inside); |
| 24 | + } |
| 25 | + |
| 26 | + public static Affinities of(Error inside) { |
| 27 | + return new AffinitiesError(inside); |
| 28 | + } |
| 29 | + |
| 30 | + public static class AffinitiesSerializer extends StdSerializer<Affinities> { |
| 31 | + |
| 32 | + public AffinitiesSerializer(Class<Affinities> t) { |
| 33 | + super(t); |
| 34 | + } |
| 35 | + |
| 36 | + public AffinitiesSerializer() { |
| 37 | + this(null); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void serialize(Affinities value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { |
| 42 | + jgen.writeObject(value.getInsideValue()); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public static class AffinitiesDeserializer extends StdDeserializer<Affinities> { |
| 47 | + |
| 48 | + public AffinitiesDeserializer() { |
| 49 | + this(Affinities.class); |
| 50 | + } |
| 51 | + |
| 52 | + public AffinitiesDeserializer(Class<?> vc) { |
| 53 | + super(vc); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public Affinities deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { |
| 58 | + JsonNode tree = jp.readValueAsTree(); |
| 59 | + Affinities deserialized = null; |
| 60 | + |
| 61 | + int match = 0; |
| 62 | + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); |
| 63 | + String currentType = ""; |
| 64 | + // deserialize AffinitiesSuccess |
| 65 | + try { |
| 66 | + boolean attemptParsing = true; |
| 67 | + currentType = "AffinitiesSuccess"; |
| 68 | + if ( |
| 69 | + ((currentType.equals("Integer") || currentType.equals("Long")) && token == JsonToken.VALUE_NUMBER_INT) | |
| 70 | + ((currentType.equals("Float") || currentType.equals("Double")) && token == JsonToken.VALUE_NUMBER_FLOAT) | |
| 71 | + (currentType.equals("Boolean") && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)) | |
| 72 | + (currentType.equals("String") && token == JsonToken.VALUE_STRING) | |
| 73 | + (currentType.startsWith("List<") && token == JsonToken.START_ARRAY) |
| 74 | + ) { |
| 75 | + deserialized = |
| 76 | + Affinities.of((AffinitiesSuccess) tree.traverse(jp.getCodec()).readValueAs(new TypeReference<AffinitiesSuccess>() {})); |
| 77 | + match++; |
| 78 | + } else if (token == JsonToken.START_OBJECT) { |
| 79 | + try { |
| 80 | + deserialized = |
| 81 | + Affinities.of((AffinitiesSuccess) tree.traverse(jp.getCodec()).readValueAs(new TypeReference<AffinitiesSuccess>() {})); |
| 82 | + match++; |
| 83 | + } catch (IOException e) { |
| 84 | + // do nothing |
| 85 | + } |
| 86 | + } |
| 87 | + } catch (Exception e) { |
| 88 | + // deserialization failed, continue |
| 89 | + System.err.println("Failed to deserialize oneOf AffinitiesSuccess (error: " + e.getMessage() + ") (type: " + currentType + ")"); |
| 90 | + } |
| 91 | + |
| 92 | + // deserialize Error |
| 93 | + try { |
| 94 | + boolean attemptParsing = true; |
| 95 | + currentType = "Error"; |
| 96 | + if ( |
| 97 | + ((currentType.equals("Integer") || currentType.equals("Long")) && token == JsonToken.VALUE_NUMBER_INT) | |
| 98 | + ((currentType.equals("Float") || currentType.equals("Double")) && token == JsonToken.VALUE_NUMBER_FLOAT) | |
| 99 | + (currentType.equals("Boolean") && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)) | |
| 100 | + (currentType.equals("String") && token == JsonToken.VALUE_STRING) | |
| 101 | + (currentType.startsWith("List<") && token == JsonToken.START_ARRAY) |
| 102 | + ) { |
| 103 | + deserialized = Affinities.of((Error) tree.traverse(jp.getCodec()).readValueAs(new TypeReference<Error>() {})); |
| 104 | + match++; |
| 105 | + } else if (token == JsonToken.START_OBJECT) { |
| 106 | + try { |
| 107 | + deserialized = Affinities.of((Error) tree.traverse(jp.getCodec()).readValueAs(new TypeReference<Error>() {})); |
| 108 | + match++; |
| 109 | + } catch (IOException e) { |
| 110 | + // do nothing |
| 111 | + } |
| 112 | + } |
| 113 | + } catch (Exception e) { |
| 114 | + // deserialization failed, continue |
| 115 | + System.err.println("Failed to deserialize oneOf Error (error: " + e.getMessage() + ") (type: " + currentType + ")"); |
| 116 | + } |
| 117 | + |
| 118 | + if (match == 1) { |
| 119 | + return deserialized; |
| 120 | + } |
| 121 | + throw new IOException(String.format("Failed deserialization for Affinities: %d classes match result, expected 1", match)); |
| 122 | + } |
| 123 | + |
| 124 | + /** Handle deserialization of the 'null' value. */ |
| 125 | + @Override |
| 126 | + public Affinities getNullValue(DeserializationContext ctxt) throws JsonMappingException { |
| 127 | + throw new JsonMappingException(ctxt.getParser(), "Affinities cannot be null"); |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +class AffinitiesAffinitiesSuccess extends Affinities { |
| 133 | + |
| 134 | + private final AffinitiesSuccess insideValue; |
| 135 | + |
| 136 | + AffinitiesAffinitiesSuccess(AffinitiesSuccess insideValue) { |
| 137 | + this.insideValue = insideValue; |
| 138 | + } |
| 139 | + |
| 140 | + @Override |
| 141 | + public AffinitiesSuccess getInsideValue() { |
| 142 | + return insideValue; |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +class AffinitiesError extends Affinities { |
| 147 | + |
| 148 | + private final Error insideValue; |
| 149 | + |
| 150 | + AffinitiesError(Error insideValue) { |
| 151 | + this.insideValue = insideValue; |
| 152 | + } |
| 153 | + |
| 154 | + @Override |
| 155 | + public Error getInsideValue() { |
| 156 | + return insideValue; |
| 157 | + } |
| 158 | +} |
0 commit comments