All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.factset.sdk.SecurityModeling.models.OneOfSMFields Maven / Gradle / Ivy

There is a newer version: 0.21.2
Show newest version
/*
 * 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 = OneOfSMFields.OneOfSMFieldsDeserializer.class)
@JsonSerialize(using = OneOfSMFields.OneOfSMFieldsSerializer.class)
public class OneOfSMFields extends AbstractOpenApiSchema implements Serializable {
    private static final Logger log = Logger.getLogger(OneOfSMFields.class.getName());

    public static class OneOfSMFieldsSerializer extends StdSerializer {
        public OneOfSMFieldsSerializer(Class t) {
            super(t);
        }

        public OneOfSMFieldsSerializer() {
            this(null);
        }

        @Override
        public void serialize(OneOfSMFields value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
            jgen.writeObject(value.getActualInstance());
        }
    }

    public static class OneOfSMFieldsDeserializer extends StdDeserializer {
        public OneOfSMFieldsDeserializer() {
            this(OneOfSMFields.class);
        }

        public OneOfSMFieldsDeserializer(Class vc) {
            super(vc);
        }

        @Override
        public OneOfSMFields deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
            JsonNode tree = jp.readValueAsTree();
            Object deserialized = null;
            OneOfSMFields newOneOfSMFields = new OneOfSMFields();
            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);
                    newOneOfSMFields.setActualInstance(deserialized);
                    return newOneOfSMFields;
                case "CCF":
                    deserialized = tree.traverse(jp.getCodec()).readValueAs(SMCustomCashFlowFields.class);
                    newOneOfSMFields.setActualInstance(deserialized);
                    return newOneOfSMFields;
                case "SMBondFields":
                    deserialized = tree.traverse(jp.getCodec()).readValueAs(SMBondFields.class);
                    newOneOfSMFields.setActualInstance(deserialized);
                    return newOneOfSMFields;
                case "SMCustomCashFlowFields":
                    deserialized = tree.traverse(jp.getCodec()).readValueAs(SMCustomCashFlowFields.class);
                    newOneOfSMFields.setActualInstance(deserialized);
                    return newOneOfSMFields;
                default:
                    log.log(Level.WARNING, String.format("Failed to lookup discriminator value `%s` for OneOfSMFields. 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) {
                OneOfSMFields ret = new OneOfSMFields();
                ret.setActualInstance(deserialized);
                return ret;
            }
            throw new IOException(String.format("Failed deserialization for OneOfSMFields: %d classes match result, expected 1", match));
        }

        /**
         * Handle deserialization of the 'null' value.
         */
        @Override
        public OneOfSMFields getNullValue(DeserializationContext ctxt) throws JsonMappingException {
            throw new JsonMappingException(ctxt.getParser(), "OneOfSMFields cannot be null");
        }
    }

    // store a list of schema names defined in oneOf
    public static final Map schemas = new HashMap();

    public OneOfSMFields() {
        super("oneOf", Boolean.FALSE);
    }

    public OneOfSMFields(SMBondFields o) {
        super("oneOf", Boolean.FALSE);
        setActualInstance(o);
    }
    public OneOfSMFields(SMCustomCashFlowFields o) {
        super("oneOf", Boolean.FALSE);
        setActualInstance(o);
    }
    static {
        schemas.put("SMBondFields", new GenericType() {
        });
        schemas.put("SMCustomCashFlowFields", new GenericType() {
        });
        JSON.registerDescendants(OneOfSMFields.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("OneOfSMFields", OneOfSMFields.class);
        JSON.registerDiscriminator(OneOfSMFields.class, "securityType", mappings);
    }

    @Override
    public Map getSchemas() {
        return OneOfSMFields.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) {
        // 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();
    }

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy