Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.factset.sdk.SecurityModeling.models.OneOfFieldsFields Maven / Gradle / Ivy
/*
* Security-Modeling API
* Allow clients to fetch Analytics through APIs.
*
* The version of the OpenAPI document: 3
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package com.factset.sdk.SecurityModeling.models;
import java.util.Objects;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import com.factset.sdk.SecurityModeling.models.SMBondFields;
import com.factset.sdk.SecurityModeling.models.SMCustomCashFlowFields;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.factset.sdk.SecurityModeling.JSON;
import com.fasterxml.jackson.core.type.TypeReference;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.math.BigDecimal;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.factset.sdk.SecurityModeling.JSON;
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
@JsonDeserialize(using = OneOfFieldsFields.OneOfFieldsFieldsDeserializer.class)
@JsonSerialize(using = OneOfFieldsFields.OneOfFieldsFieldsSerializer.class)
public class OneOfFieldsFields extends AbstractOpenApiSchema implements Serializable {
private static final Logger log = Logger.getLogger(OneOfFieldsFields.class.getName());
public static class OneOfFieldsFieldsSerializer extends StdSerializer {
public OneOfFieldsFieldsSerializer(Class t) {
super(t);
}
public OneOfFieldsFieldsSerializer() {
this(null);
}
@Override
public void serialize(OneOfFieldsFields value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeObject(value.getActualInstance());
}
}
public static class OneOfFieldsFieldsDeserializer extends StdDeserializer {
public OneOfFieldsFieldsDeserializer() {
this(OneOfFieldsFields.class);
}
public OneOfFieldsFieldsDeserializer(Class> vc) {
super(vc);
}
@Override
public OneOfFieldsFields deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode tree = jp.readValueAsTree();
Object deserialized = null;
OneOfFieldsFields newOneOfFieldsFields = new OneOfFieldsFields();
Map result2 = tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {});
String discriminatorValue = (String)result2.get("securityType");
switch (discriminatorValue) {
case "Bond":
deserialized = tree.traverse(jp.getCodec()).readValueAs(SMBondFields.class);
newOneOfFieldsFields.setActualInstance(deserialized);
return newOneOfFieldsFields;
case "CCF":
deserialized = tree.traverse(jp.getCodec()).readValueAs(SMCustomCashFlowFields.class);
newOneOfFieldsFields.setActualInstance(deserialized);
return newOneOfFieldsFields;
case "SMBondFields":
deserialized = tree.traverse(jp.getCodec()).readValueAs(SMBondFields.class);
newOneOfFieldsFields.setActualInstance(deserialized);
return newOneOfFieldsFields;
case "SMCustomCashFlowFields":
deserialized = tree.traverse(jp.getCodec()).readValueAs(SMCustomCashFlowFields.class);
newOneOfFieldsFields.setActualInstance(deserialized);
return newOneOfFieldsFields;
default:
log.log(Level.WARNING, String.format("Failed to lookup discriminator value `%s` for OneOfFieldsFields. Possible values: Bond CCF SMBondFields SMCustomCashFlowFields", discriminatorValue));
}
boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS);
int match = 0;
JsonToken token = tree.traverse(jp.getCodec()).nextToken();
// deserialize SMBondFields
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
if (SMBondFields.class.equals(Integer.class) || SMBondFields.class.equals(Long.class) || SMBondFields.class.equals(Float.class) || SMBondFields.class.equals(Double.class) || SMBondFields.class.equals(Boolean.class) || SMBondFields.class.equals(String.class)) {
attemptParsing = typeCoercion;
if (!attemptParsing) {
attemptParsing |= ((SMBondFields.class.equals(Integer.class) || SMBondFields.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
attemptParsing |= ((SMBondFields.class.equals(Float.class) || SMBondFields.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
attemptParsing |= (SMBondFields.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
attemptParsing |= (SMBondFields.class.equals(String.class) && token == JsonToken.VALUE_STRING);
}
}
if (attemptParsing) {
deserialized = tree.traverse(jp.getCodec()).readValueAs(new TypeReference() { });
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
match++;
log.log(Level.FINER, "Input data matches schema 'SMBondFields'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'SMBondFields'", e);
}
// deserialize SMCustomCashFlowFields
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
if (SMCustomCashFlowFields.class.equals(Integer.class) || SMCustomCashFlowFields.class.equals(Long.class) || SMCustomCashFlowFields.class.equals(Float.class) || SMCustomCashFlowFields.class.equals(Double.class) || SMCustomCashFlowFields.class.equals(Boolean.class) || SMCustomCashFlowFields.class.equals(String.class)) {
attemptParsing = typeCoercion;
if (!attemptParsing) {
attemptParsing |= ((SMCustomCashFlowFields.class.equals(Integer.class) || SMCustomCashFlowFields.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
attemptParsing |= ((SMCustomCashFlowFields.class.equals(Float.class) || SMCustomCashFlowFields.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
attemptParsing |= (SMCustomCashFlowFields.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
attemptParsing |= (SMCustomCashFlowFields.class.equals(String.class) && token == JsonToken.VALUE_STRING);
}
}
if (attemptParsing) {
deserialized = tree.traverse(jp.getCodec()).readValueAs(new TypeReference() { });
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
match++;
log.log(Level.FINER, "Input data matches schema 'SMCustomCashFlowFields'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'SMCustomCashFlowFields'", e);
}
if (match == 1) {
OneOfFieldsFields ret = new OneOfFieldsFields();
ret.setActualInstance(deserialized);
return ret;
}
throw new IOException(String.format("Failed deserialization for OneOfFieldsFields: %d classes match result, expected 1", match));
}
/**
* Handle deserialization of the 'null' value.
*/
@Override
public OneOfFieldsFields getNullValue(DeserializationContext ctxt) throws JsonMappingException {
return null;
}
}
// store a list of schema names defined in oneOf
public static final Map schemas = new HashMap();
public OneOfFieldsFields() {
super("oneOf", Boolean.TRUE);
}
public OneOfFieldsFields(SMBondFields o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
public OneOfFieldsFields(SMCustomCashFlowFields o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
static {
schemas.put("SMBondFields", new GenericType() {
});
schemas.put("SMCustomCashFlowFields", new GenericType() {
});
JSON.registerDescendants(OneOfFieldsFields.class, Collections.unmodifiableMap(schemas));
// Initialize and register the discriminator mappings.
Map> mappings = new HashMap>();
mappings.put("Bond", SMBondFields.class);
mappings.put("CCF", SMCustomCashFlowFields.class);
mappings.put("SMBondFields", SMBondFields.class);
mappings.put("SMCustomCashFlowFields", SMCustomCashFlowFields.class);
mappings.put("OneOfFieldsFields", OneOfFieldsFields.class);
JSON.registerDiscriminator(OneOfFieldsFields.class, "securityType", mappings);
}
@Override
public Map getSchemas() {
return OneOfFieldsFields.schemas;
}
/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas:
* SMBondFields, SMCustomCashFlowFields
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
*/
@Override
public void setActualInstance(Object instance) {
if (instance == null) {
super.setActualInstance(instance);
return;
}
// SMBondFields
if (JSON.isInstanceOf(SMBondFields.class, instance, new HashSet>())) {
super.setActualInstance(instance);
return;
}
// SMCustomCashFlowFields
if (JSON.isInstanceOf(SMCustomCashFlowFields.class, instance, new HashSet>())) {
super.setActualInstance(instance);
return;
}
throw new RuntimeException("Invalid instance type. Must be SMBondFields, SMCustomCashFlowFields");
}
/**
* Get the actual instance, which can be the following:
* SMBondFields, SMCustomCashFlowFields
*
* @return The actual instance (SMBondFields, SMCustomCashFlowFields)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}
/**
* Get the actual instance of `SMBondFields`. If the actual instance is not `SMBondFields`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `SMBondFields`
* @throws ClassCastException if the instance is not `SMBondFields`
*/
public SMBondFields getSMBondFields() throws ClassCastException {
return (SMBondFields)super.getActualInstance();
}
/**
* Get the actual instance of `SMCustomCashFlowFields`. If the actual instance is not `SMCustomCashFlowFields`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `SMCustomCashFlowFields`
* @throws ClassCastException if the instance is not `SMCustomCashFlowFields`
*/
public SMCustomCashFlowFields getSMCustomCashFlowFields() throws ClassCastException {
return (SMCustomCashFlowFields)super.getActualInstance();
}
}