|
| 1 | +/* |
| 2 | + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 3 | + * This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 4 | + * Copyright 2019-Present Datadog, Inc. |
| 5 | + */ |
| 6 | + |
| 7 | +package com.datadog.api.client.v1.model; |
| 8 | + |
| 9 | +import com.datadog.api.client.AbstractOpenApiSchema; |
| 10 | +import com.datadog.api.client.JSON; |
| 11 | +import com.datadog.api.client.UnparsedObject; |
| 12 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
| 13 | +import com.fasterxml.jackson.core.JsonGenerator; |
| 14 | +import com.fasterxml.jackson.core.JsonParser; |
| 15 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 16 | +import com.fasterxml.jackson.core.JsonToken; |
| 17 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 18 | +import com.fasterxml.jackson.databind.DeserializationContext; |
| 19 | +import com.fasterxml.jackson.databind.JsonMappingException; |
| 20 | +import com.fasterxml.jackson.databind.JsonNode; |
| 21 | +import com.fasterxml.jackson.databind.MapperFeature; |
| 22 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 23 | +import com.fasterxml.jackson.databind.SerializerProvider; |
| 24 | +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| 25 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| 26 | +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; |
| 27 | +import com.fasterxml.jackson.databind.ser.std.StdSerializer; |
| 28 | +import jakarta.ws.rs.core.GenericType; |
| 29 | +import java.io.IOException; |
| 30 | +import java.util.Collections; |
| 31 | +import java.util.HashMap; |
| 32 | +import java.util.HashSet; |
| 33 | +import java.util.Map; |
| 34 | +import java.util.logging.Level; |
| 35 | +import java.util.logging.Logger; |
| 36 | + |
| 37 | +@jakarta.annotation.Generated( |
| 38 | + value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator") |
| 39 | +@JsonDeserialize(using = GuidedTableColumn.GuidedTableColumnDeserializer.class) |
| 40 | +@JsonSerialize(using = GuidedTableColumn.GuidedTableColumnSerializer.class) |
| 41 | +public class GuidedTableColumn extends AbstractOpenApiSchema { |
| 42 | + private static final Logger log = Logger.getLogger(GuidedTableColumn.class.getName()); |
| 43 | + |
| 44 | + @JsonIgnore public boolean unparsed = false; |
| 45 | + |
| 46 | + public static class GuidedTableColumnSerializer extends StdSerializer<GuidedTableColumn> { |
| 47 | + public GuidedTableColumnSerializer(Class<GuidedTableColumn> t) { |
| 48 | + super(t); |
| 49 | + } |
| 50 | + |
| 51 | + public GuidedTableColumnSerializer() { |
| 52 | + this(null); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void serialize(GuidedTableColumn value, JsonGenerator jgen, SerializerProvider provider) |
| 57 | + throws IOException, JsonProcessingException { |
| 58 | + jgen.writeObject(value.getActualInstance()); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + public static class GuidedTableColumnDeserializer extends StdDeserializer<GuidedTableColumn> { |
| 63 | + public GuidedTableColumnDeserializer() { |
| 64 | + this(GuidedTableColumn.class); |
| 65 | + } |
| 66 | + |
| 67 | + public GuidedTableColumnDeserializer(Class<?> vc) { |
| 68 | + super(vc); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public GuidedTableColumn deserialize(JsonParser jp, DeserializationContext ctxt) |
| 73 | + throws IOException, JsonProcessingException { |
| 74 | + JsonNode tree = jp.readValueAsTree(); |
| 75 | + Object deserialized = null; |
| 76 | + Object tmp = null; |
| 77 | + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); |
| 78 | + int match = 0; |
| 79 | + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); |
| 80 | + // deserialize GuidedTableComputeColumn |
| 81 | + try { |
| 82 | + boolean attemptParsing = true; |
| 83 | + // ensure that we respect type coercion as set on the client ObjectMapper |
| 84 | + if (GuidedTableComputeColumn.class.equals(Integer.class) |
| 85 | + || GuidedTableComputeColumn.class.equals(Long.class) |
| 86 | + || GuidedTableComputeColumn.class.equals(Float.class) |
| 87 | + || GuidedTableComputeColumn.class.equals(Double.class) |
| 88 | + || GuidedTableComputeColumn.class.equals(Boolean.class) |
| 89 | + || GuidedTableComputeColumn.class.equals(String.class)) { |
| 90 | + attemptParsing = typeCoercion; |
| 91 | + if (!attemptParsing) { |
| 92 | + attemptParsing |= |
| 93 | + ((GuidedTableComputeColumn.class.equals(Integer.class) |
| 94 | + || GuidedTableComputeColumn.class.equals(Long.class)) |
| 95 | + && token == JsonToken.VALUE_NUMBER_INT); |
| 96 | + attemptParsing |= |
| 97 | + ((GuidedTableComputeColumn.class.equals(Float.class) |
| 98 | + || GuidedTableComputeColumn.class.equals(Double.class)) |
| 99 | + && (token == JsonToken.VALUE_NUMBER_FLOAT |
| 100 | + || token == JsonToken.VALUE_NUMBER_INT)); |
| 101 | + attemptParsing |= |
| 102 | + (GuidedTableComputeColumn.class.equals(Boolean.class) |
| 103 | + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); |
| 104 | + attemptParsing |= |
| 105 | + (GuidedTableComputeColumn.class.equals(String.class) |
| 106 | + && token == JsonToken.VALUE_STRING); |
| 107 | + } |
| 108 | + } |
| 109 | + if (attemptParsing) { |
| 110 | + tmp = tree.traverse(jp.getCodec()).readValueAs(GuidedTableComputeColumn.class); |
| 111 | + // TODO: there is no validation against JSON schema constraints |
| 112 | + // (min, max, enum, pattern...), this does not perform a strict JSON |
| 113 | + // validation, which means the 'match' count may be higher than it should be. |
| 114 | + if (!((GuidedTableComputeColumn) tmp).unparsed) { |
| 115 | + deserialized = tmp; |
| 116 | + match++; |
| 117 | + } |
| 118 | + log.log(Level.FINER, "Input data matches schema 'GuidedTableComputeColumn'"); |
| 119 | + } |
| 120 | + } catch (Exception e) { |
| 121 | + // deserialization failed, continue |
| 122 | + log.log(Level.FINER, "Input data does not match schema 'GuidedTableComputeColumn'", e); |
| 123 | + } |
| 124 | + |
| 125 | + // deserialize GuidedTablePresetColumn |
| 126 | + try { |
| 127 | + boolean attemptParsing = true; |
| 128 | + // ensure that we respect type coercion as set on the client ObjectMapper |
| 129 | + if (GuidedTablePresetColumn.class.equals(Integer.class) |
| 130 | + || GuidedTablePresetColumn.class.equals(Long.class) |
| 131 | + || GuidedTablePresetColumn.class.equals(Float.class) |
| 132 | + || GuidedTablePresetColumn.class.equals(Double.class) |
| 133 | + || GuidedTablePresetColumn.class.equals(Boolean.class) |
| 134 | + || GuidedTablePresetColumn.class.equals(String.class)) { |
| 135 | + attemptParsing = typeCoercion; |
| 136 | + if (!attemptParsing) { |
| 137 | + attemptParsing |= |
| 138 | + ((GuidedTablePresetColumn.class.equals(Integer.class) |
| 139 | + || GuidedTablePresetColumn.class.equals(Long.class)) |
| 140 | + && token == JsonToken.VALUE_NUMBER_INT); |
| 141 | + attemptParsing |= |
| 142 | + ((GuidedTablePresetColumn.class.equals(Float.class) |
| 143 | + || GuidedTablePresetColumn.class.equals(Double.class)) |
| 144 | + && (token == JsonToken.VALUE_NUMBER_FLOAT |
| 145 | + || token == JsonToken.VALUE_NUMBER_INT)); |
| 146 | + attemptParsing |= |
| 147 | + (GuidedTablePresetColumn.class.equals(Boolean.class) |
| 148 | + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); |
| 149 | + attemptParsing |= |
| 150 | + (GuidedTablePresetColumn.class.equals(String.class) |
| 151 | + && token == JsonToken.VALUE_STRING); |
| 152 | + } |
| 153 | + } |
| 154 | + if (attemptParsing) { |
| 155 | + tmp = tree.traverse(jp.getCodec()).readValueAs(GuidedTablePresetColumn.class); |
| 156 | + // TODO: there is no validation against JSON schema constraints |
| 157 | + // (min, max, enum, pattern...), this does not perform a strict JSON |
| 158 | + // validation, which means the 'match' count may be higher than it should be. |
| 159 | + if (!((GuidedTablePresetColumn) tmp).unparsed) { |
| 160 | + deserialized = tmp; |
| 161 | + match++; |
| 162 | + } |
| 163 | + log.log(Level.FINER, "Input data matches schema 'GuidedTablePresetColumn'"); |
| 164 | + } |
| 165 | + } catch (Exception e) { |
| 166 | + // deserialization failed, continue |
| 167 | + log.log(Level.FINER, "Input data does not match schema 'GuidedTablePresetColumn'", e); |
| 168 | + } |
| 169 | + |
| 170 | + // deserialize GuidedTableFormulaColumn |
| 171 | + try { |
| 172 | + boolean attemptParsing = true; |
| 173 | + // ensure that we respect type coercion as set on the client ObjectMapper |
| 174 | + if (GuidedTableFormulaColumn.class.equals(Integer.class) |
| 175 | + || GuidedTableFormulaColumn.class.equals(Long.class) |
| 176 | + || GuidedTableFormulaColumn.class.equals(Float.class) |
| 177 | + || GuidedTableFormulaColumn.class.equals(Double.class) |
| 178 | + || GuidedTableFormulaColumn.class.equals(Boolean.class) |
| 179 | + || GuidedTableFormulaColumn.class.equals(String.class)) { |
| 180 | + attemptParsing = typeCoercion; |
| 181 | + if (!attemptParsing) { |
| 182 | + attemptParsing |= |
| 183 | + ((GuidedTableFormulaColumn.class.equals(Integer.class) |
| 184 | + || GuidedTableFormulaColumn.class.equals(Long.class)) |
| 185 | + && token == JsonToken.VALUE_NUMBER_INT); |
| 186 | + attemptParsing |= |
| 187 | + ((GuidedTableFormulaColumn.class.equals(Float.class) |
| 188 | + || GuidedTableFormulaColumn.class.equals(Double.class)) |
| 189 | + && (token == JsonToken.VALUE_NUMBER_FLOAT |
| 190 | + || token == JsonToken.VALUE_NUMBER_INT)); |
| 191 | + attemptParsing |= |
| 192 | + (GuidedTableFormulaColumn.class.equals(Boolean.class) |
| 193 | + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); |
| 194 | + attemptParsing |= |
| 195 | + (GuidedTableFormulaColumn.class.equals(String.class) |
| 196 | + && token == JsonToken.VALUE_STRING); |
| 197 | + } |
| 198 | + } |
| 199 | + if (attemptParsing) { |
| 200 | + tmp = tree.traverse(jp.getCodec()).readValueAs(GuidedTableFormulaColumn.class); |
| 201 | + // TODO: there is no validation against JSON schema constraints |
| 202 | + // (min, max, enum, pattern...), this does not perform a strict JSON |
| 203 | + // validation, which means the 'match' count may be higher than it should be. |
| 204 | + if (!((GuidedTableFormulaColumn) tmp).unparsed) { |
| 205 | + deserialized = tmp; |
| 206 | + match++; |
| 207 | + } |
| 208 | + log.log(Level.FINER, "Input data matches schema 'GuidedTableFormulaColumn'"); |
| 209 | + } |
| 210 | + } catch (Exception e) { |
| 211 | + // deserialization failed, continue |
| 212 | + log.log(Level.FINER, "Input data does not match schema 'GuidedTableFormulaColumn'", e); |
| 213 | + } |
| 214 | + |
| 215 | + GuidedTableColumn ret = new GuidedTableColumn(); |
| 216 | + if (match == 1) { |
| 217 | + ret.setActualInstance(deserialized); |
| 218 | + } else { |
| 219 | + Map<String, Object> res = |
| 220 | + new ObjectMapper() |
| 221 | + .readValue( |
| 222 | + tree.traverse(jp.getCodec()).readValueAsTree().toString(), |
| 223 | + new TypeReference<Map<String, Object>>() {}); |
| 224 | + ret.setActualInstance(new UnparsedObject(res)); |
| 225 | + } |
| 226 | + return ret; |
| 227 | + } |
| 228 | + |
| 229 | + /** Handle deserialization of the 'null' value. */ |
| 230 | + @Override |
| 231 | + public GuidedTableColumn getNullValue(DeserializationContext ctxt) throws JsonMappingException { |
| 232 | + throw new JsonMappingException(ctxt.getParser(), "GuidedTableColumn cannot be null"); |
| 233 | + } |
| 234 | + } |
| 235 | + |
| 236 | + // store a list of schema names defined in oneOf |
| 237 | + public static final Map<String, GenericType> schemas = new HashMap<String, GenericType>(); |
| 238 | + |
| 239 | + public GuidedTableColumn() { |
| 240 | + super("oneOf", Boolean.FALSE); |
| 241 | + } |
| 242 | + |
| 243 | + public GuidedTableColumn(GuidedTableComputeColumn o) { |
| 244 | + super("oneOf", Boolean.FALSE); |
| 245 | + setActualInstance(o); |
| 246 | + } |
| 247 | + |
| 248 | + public GuidedTableColumn(GuidedTablePresetColumn o) { |
| 249 | + super("oneOf", Boolean.FALSE); |
| 250 | + setActualInstance(o); |
| 251 | + } |
| 252 | + |
| 253 | + public GuidedTableColumn(GuidedTableFormulaColumn o) { |
| 254 | + super("oneOf", Boolean.FALSE); |
| 255 | + setActualInstance(o); |
| 256 | + } |
| 257 | + |
| 258 | + static { |
| 259 | + schemas.put("GuidedTableComputeColumn", new GenericType<GuidedTableComputeColumn>() {}); |
| 260 | + schemas.put("GuidedTablePresetColumn", new GenericType<GuidedTablePresetColumn>() {}); |
| 261 | + schemas.put("GuidedTableFormulaColumn", new GenericType<GuidedTableFormulaColumn>() {}); |
| 262 | + JSON.registerDescendants(GuidedTableColumn.class, Collections.unmodifiableMap(schemas)); |
| 263 | + } |
| 264 | + |
| 265 | + @Override |
| 266 | + public Map<String, GenericType> getSchemas() { |
| 267 | + return GuidedTableColumn.schemas; |
| 268 | + } |
| 269 | + |
| 270 | + /** |
| 271 | + * Set the instance that matches the oneOf child schema, check the instance parameter is valid |
| 272 | + * against the oneOf child schemas: GuidedTableComputeColumn, GuidedTablePresetColumn, |
| 273 | + * GuidedTableFormulaColumn |
| 274 | + * |
| 275 | + * <p>It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a |
| 276 | + * composed schema (allOf, anyOf, oneOf). |
| 277 | + */ |
| 278 | + @Override |
| 279 | + public void setActualInstance(Object instance) { |
| 280 | + if (JSON.isInstanceOf(GuidedTableComputeColumn.class, instance, new HashSet<Class<?>>())) { |
| 281 | + super.setActualInstance(instance); |
| 282 | + return; |
| 283 | + } |
| 284 | + if (JSON.isInstanceOf(GuidedTablePresetColumn.class, instance, new HashSet<Class<?>>())) { |
| 285 | + super.setActualInstance(instance); |
| 286 | + return; |
| 287 | + } |
| 288 | + if (JSON.isInstanceOf(GuidedTableFormulaColumn.class, instance, new HashSet<Class<?>>())) { |
| 289 | + super.setActualInstance(instance); |
| 290 | + return; |
| 291 | + } |
| 292 | + |
| 293 | + if (JSON.isInstanceOf(UnparsedObject.class, instance, new HashSet<Class<?>>())) { |
| 294 | + super.setActualInstance(instance); |
| 295 | + return; |
| 296 | + } |
| 297 | + throw new RuntimeException( |
| 298 | + "Invalid instance type. Must be GuidedTableComputeColumn, GuidedTablePresetColumn," |
| 299 | + + " GuidedTableFormulaColumn"); |
| 300 | + } |
| 301 | + |
| 302 | + /** |
| 303 | + * Get the actual instance, which can be the following: GuidedTableComputeColumn, |
| 304 | + * GuidedTablePresetColumn, GuidedTableFormulaColumn |
| 305 | + * |
| 306 | + * @return The actual instance (GuidedTableComputeColumn, GuidedTablePresetColumn, |
| 307 | + * GuidedTableFormulaColumn) |
| 308 | + */ |
| 309 | + @Override |
| 310 | + public Object getActualInstance() { |
| 311 | + return super.getActualInstance(); |
| 312 | + } |
| 313 | + |
| 314 | + /** |
| 315 | + * Get the actual instance of `GuidedTableComputeColumn`. If the actual instance is not |
| 316 | + * `GuidedTableComputeColumn`, the ClassCastException will be thrown. |
| 317 | + * |
| 318 | + * @return The actual instance of `GuidedTableComputeColumn` |
| 319 | + * @throws ClassCastException if the instance is not `GuidedTableComputeColumn` |
| 320 | + */ |
| 321 | + public GuidedTableComputeColumn getGuidedTableComputeColumn() throws ClassCastException { |
| 322 | + return (GuidedTableComputeColumn) super.getActualInstance(); |
| 323 | + } |
| 324 | + |
| 325 | + /** |
| 326 | + * Get the actual instance of `GuidedTablePresetColumn`. If the actual instance is not |
| 327 | + * `GuidedTablePresetColumn`, the ClassCastException will be thrown. |
| 328 | + * |
| 329 | + * @return The actual instance of `GuidedTablePresetColumn` |
| 330 | + * @throws ClassCastException if the instance is not `GuidedTablePresetColumn` |
| 331 | + */ |
| 332 | + public GuidedTablePresetColumn getGuidedTablePresetColumn() throws ClassCastException { |
| 333 | + return (GuidedTablePresetColumn) super.getActualInstance(); |
| 334 | + } |
| 335 | + |
| 336 | + /** |
| 337 | + * Get the actual instance of `GuidedTableFormulaColumn`. If the actual instance is not |
| 338 | + * `GuidedTableFormulaColumn`, the ClassCastException will be thrown. |
| 339 | + * |
| 340 | + * @return The actual instance of `GuidedTableFormulaColumn` |
| 341 | + * @throws ClassCastException if the instance is not `GuidedTableFormulaColumn` |
| 342 | + */ |
| 343 | + public GuidedTableFormulaColumn getGuidedTableFormulaColumn() throws ClassCastException { |
| 344 | + return (GuidedTableFormulaColumn) super.getActualInstance(); |
| 345 | + } |
| 346 | +} |
0 commit comments