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

com.sinch.sdk.domains.sms.models.dto.v1.SendSMS201ResponseDto Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
/*
 * API Overview | Sinch
 * Sinch SMS API is one of the easiest APIs we offer and enables you to add fast and reliable global SMS to your applications. Send single messages, scheduled batch messages, use available message templates and more.
 *
 * The version of the OpenAPI document: v1
 * 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.sinch.sdk.domains.sms.models.dto.v1;

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.sinch.sdk.core.models.AbstractOpenApiSchema;
import com.sinch.sdk.core.utils.databind.JSONNavigator;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

@JsonDeserialize(using = SendSMS201ResponseDto.SendSMS201ResponseDtoDeserializer.class)
@JsonSerialize(using = SendSMS201ResponseDto.SendSMS201ResponseDtoSerializer.class)
public final class SendSMS201ResponseDto extends AbstractOpenApiSchema {
  private static final Logger log = Logger.getLogger(SendSMS201ResponseDto.class.getName());

  public static final class SendSMS201ResponseDtoSerializer
      extends StdSerializer {
    private static final long serialVersionUID = 1L;

    public SendSMS201ResponseDtoSerializer(Class t) {
      super(t);
    }

    public SendSMS201ResponseDtoSerializer() {
      this(null);
    }

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

  public static final class SendSMS201ResponseDtoDeserializer
      extends StdDeserializer {

    private static final long serialVersionUID = 1L;

    public SendSMS201ResponseDtoDeserializer() {
      this(SendSMS201ResponseDto.class);
    }

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

    @Override
    public SendSMS201ResponseDto deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
      JsonNode tree = jp.readValueAsTree();
      Object deserialized = null;
      SendSMS201ResponseDto newSendSMS201ResponseDto = new SendSMS201ResponseDto();
      Map result2 =
          tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {});
      String discriminatorValue = (String) result2.get("type");
      switch (discriminatorValue) {
        case "BinaryResponse":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryResponseDto.class);
          newSendSMS201ResponseDto.setActualInstance(deserialized);
          return newSendSMS201ResponseDto;
        case "MediaResponse":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaResponseDto.class);
          newSendSMS201ResponseDto.setActualInstance(deserialized);
          return newSendSMS201ResponseDto;
        case "TextResponse":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(TextResponseDto.class);
          newSendSMS201ResponseDto.setActualInstance(deserialized);
          return newSendSMS201ResponseDto;
        case "mt_binary":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryResponseDto.class);
          newSendSMS201ResponseDto.setActualInstance(deserialized);
          return newSendSMS201ResponseDto;
        case "mt_media":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaResponseDto.class);
          newSendSMS201ResponseDto.setActualInstance(deserialized);
          return newSendSMS201ResponseDto;
        case "mt_text":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(TextResponseDto.class);
          newSendSMS201ResponseDto.setActualInstance(deserialized);
          return newSendSMS201ResponseDto;
        default:
          log.log(
              Level.WARNING,
              String.format(
                  "Failed to lookup discriminator value `%s` for SendSMS201ResponseDto. Possible"
                      + " values: BinaryResponse MediaResponse TextResponse mt_binary mt_media"
                      + " mt_text",
                  discriminatorValue));
      }

      boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS);
      int match = 0;
      JsonToken token = tree.traverse(jp.getCodec()).nextToken();
      // deserialize BinaryResponseDto
      try {
        boolean attemptParsing = true;
        // ensure that we respect type coercion as set on the client ObjectMapper
        if (BinaryResponseDto.class.equals(Integer.class)
            || BinaryResponseDto.class.equals(Long.class)
            || BinaryResponseDto.class.equals(Float.class)
            || BinaryResponseDto.class.equals(Double.class)
            || BinaryResponseDto.class.equals(Boolean.class)
            || BinaryResponseDto.class.equals(String.class)) {
          attemptParsing = typeCoercion;
          if (!attemptParsing) {
            attemptParsing |=
                ((BinaryResponseDto.class.equals(Integer.class)
                        || BinaryResponseDto.class.equals(Long.class))
                    && token == JsonToken.VALUE_NUMBER_INT);
            attemptParsing |=
                ((BinaryResponseDto.class.equals(Float.class)
                        || BinaryResponseDto.class.equals(Double.class))
                    && token == JsonToken.VALUE_NUMBER_FLOAT);
            attemptParsing |=
                (BinaryResponseDto.class.equals(Boolean.class)
                    && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
            attemptParsing |=
                (BinaryResponseDto.class.equals(String.class) && token == JsonToken.VALUE_STRING);
          }
        }
        if (attemptParsing) {
          deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryResponseDto.class);
          // 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 'BinaryResponseDto'");
        }
      } catch (Exception e) {
        // deserialization failed, continue
        log.log(Level.FINER, "Input data does not match schema 'BinaryResponseDto'", e);
      }

      // deserialize MediaResponseDto
      try {
        boolean attemptParsing = true;
        // ensure that we respect type coercion as set on the client ObjectMapper
        if (MediaResponseDto.class.equals(Integer.class)
            || MediaResponseDto.class.equals(Long.class)
            || MediaResponseDto.class.equals(Float.class)
            || MediaResponseDto.class.equals(Double.class)
            || MediaResponseDto.class.equals(Boolean.class)
            || MediaResponseDto.class.equals(String.class)) {
          attemptParsing = typeCoercion;
          if (!attemptParsing) {
            attemptParsing |=
                ((MediaResponseDto.class.equals(Integer.class)
                        || MediaResponseDto.class.equals(Long.class))
                    && token == JsonToken.VALUE_NUMBER_INT);
            attemptParsing |=
                ((MediaResponseDto.class.equals(Float.class)
                        || MediaResponseDto.class.equals(Double.class))
                    && token == JsonToken.VALUE_NUMBER_FLOAT);
            attemptParsing |=
                (MediaResponseDto.class.equals(Boolean.class)
                    && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
            attemptParsing |=
                (MediaResponseDto.class.equals(String.class) && token == JsonToken.VALUE_STRING);
          }
        }
        if (attemptParsing) {
          deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaResponseDto.class);
          // 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 'MediaResponseDto'");
        }
      } catch (Exception e) {
        // deserialization failed, continue
        log.log(Level.FINER, "Input data does not match schema 'MediaResponseDto'", e);
      }

      // deserialize TextResponseDto
      try {
        boolean attemptParsing = true;
        // ensure that we respect type coercion as set on the client ObjectMapper
        if (TextResponseDto.class.equals(Integer.class)
            || TextResponseDto.class.equals(Long.class)
            || TextResponseDto.class.equals(Float.class)
            || TextResponseDto.class.equals(Double.class)
            || TextResponseDto.class.equals(Boolean.class)
            || TextResponseDto.class.equals(String.class)) {
          attemptParsing = typeCoercion;
          if (!attemptParsing) {
            attemptParsing |=
                ((TextResponseDto.class.equals(Integer.class)
                        || TextResponseDto.class.equals(Long.class))
                    && token == JsonToken.VALUE_NUMBER_INT);
            attemptParsing |=
                ((TextResponseDto.class.equals(Float.class)
                        || TextResponseDto.class.equals(Double.class))
                    && token == JsonToken.VALUE_NUMBER_FLOAT);
            attemptParsing |=
                (TextResponseDto.class.equals(Boolean.class)
                    && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
            attemptParsing |=
                (TextResponseDto.class.equals(String.class) && token == JsonToken.VALUE_STRING);
          }
        }
        if (attemptParsing) {
          deserialized = tree.traverse(jp.getCodec()).readValueAs(TextResponseDto.class);
          // 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 'TextResponseDto'");
        }
      } catch (Exception e) {
        // deserialization failed, continue
        log.log(Level.FINER, "Input data does not match schema 'TextResponseDto'", e);
      }

      if (match == 1) {
        SendSMS201ResponseDto ret = new SendSMS201ResponseDto();
        ret.setActualInstance(deserialized);
        return ret;
      }
      throw new IOException(
          String.format(
              "Failed deserialization for SendSMS201ResponseDto: %d classes match result, expected"
                  + " 1",
              match));
    }

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

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

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

  public SendSMS201ResponseDto(BinaryResponseDto o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
  }

  public SendSMS201ResponseDto(MediaResponseDto o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
  }

  public SendSMS201ResponseDto(TextResponseDto o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
  }

  static {
    schemas.put("BinaryResponseDto", BinaryResponseDto.class);
    schemas.put("MediaResponseDto", MediaResponseDto.class);
    schemas.put("TextResponseDto", TextResponseDto.class);
    JSONNavigator.registerDescendants(
        SendSMS201ResponseDto.class, Collections.unmodifiableMap(schemas));
    // Initialize and register the discriminator mappings.
    Map> mappings = new HashMap>();
    mappings.put("BinaryResponse", BinaryResponseDto.class);
    mappings.put("MediaResponse", MediaResponseDto.class);
    mappings.put("TextResponse", TextResponseDto.class);
    mappings.put("mt_binary", BinaryResponseDto.class);
    mappings.put("mt_media", MediaResponseDto.class);
    mappings.put("mt_text", TextResponseDto.class);
    mappings.put("SendSMS_201_response", SendSMS201ResponseDto.class);
    JSONNavigator.registerDiscriminator(SendSMS201ResponseDto.class, "type", mappings);
  }

  @Override
  public Map> getSchemas() {
    return SendSMS201ResponseDto.schemas;
  }

  /**
   * Set the instance that matches the oneOf child schema, check the instance parameter is valid
   * against the oneOf child schemas: BinaryResponseDto, MediaResponseDto, TextResponseDto
   *
   * 

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 (JSONNavigator.isInstanceOf(BinaryResponseDto.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } if (JSONNavigator.isInstanceOf(MediaResponseDto.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } if (JSONNavigator.isInstanceOf(TextResponseDto.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } throw new RuntimeException( "Invalid instance type. Must be BinaryResponseDto, MediaResponseDto, TextResponseDto"); } /** * Get the actual instance, which can be the following: BinaryResponseDto, MediaResponseDto, * TextResponseDto * * @return The actual instance (BinaryResponseDto, MediaResponseDto, TextResponseDto) */ @Override public Object getActualInstance() { return super.getActualInstance(); } /** * Get the actual instance of `BinaryResponseDto`. If the actual instance is not * `BinaryResponseDto`, the ClassCastException will be thrown. * * @return The actual instance of `BinaryResponseDto` * @throws ClassCastException if the instance is not `BinaryResponseDto` */ public BinaryResponseDto getBinaryResponseDto() throws ClassCastException { return (BinaryResponseDto) super.getActualInstance(); } /** * Get the actual instance of `MediaResponseDto`. If the actual instance is not * `MediaResponseDto`, the ClassCastException will be thrown. * * @return The actual instance of `MediaResponseDto` * @throws ClassCastException if the instance is not `MediaResponseDto` */ public MediaResponseDto getMediaResponseDto() throws ClassCastException { return (MediaResponseDto) super.getActualInstance(); } /** * Get the actual instance of `TextResponseDto`. If the actual instance is not `TextResponseDto`, * the ClassCastException will be thrown. * * @return The actual instance of `TextResponseDto` * @throws ClassCastException if the instance is not `TextResponseDto` */ public TextResponseDto getTextResponseDto() throws ClassCastException { return (TextResponseDto) super.getActualInstance(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy