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

com.sinch.sdk.domains.voice.models.dto.v1.WebhooksEventDto Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
/*
 * Voice API | Sinch
 * The Voice API exposes calling- and conference-related functionality in the Sinch Voice Platform.
 *
 * The version of the OpenAPI document: 1.0.1
 * 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.voice.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 = WebhooksEventDto.WebhooksEventDtoDeserializer.class)
@JsonSerialize(using = WebhooksEventDto.WebhooksEventDtoSerializer.class)
public final class WebhooksEventDto extends AbstractOpenApiSchema {
  private static final Logger log = Logger.getLogger(WebhooksEventDto.class.getName());

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

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

    public WebhooksEventDtoSerializer() {
      this(null);
    }

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

  public static final class WebhooksEventDtoDeserializer extends StdDeserializer {

    private static final long serialVersionUID = 1L;

    public WebhooksEventDtoDeserializer() {
      this(WebhooksEventDto.class);
    }

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

    @Override
    public WebhooksEventDto deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
      JsonNode tree = jp.readValueAsTree();
      Object deserialized = null;
      WebhooksEventDto newWebhooksEventDto = new WebhooksEventDto();
      Map result2 =
          tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {});
      String discriminatorValue = (String) result2.get("event");
      switch (discriminatorValue) {
        case "ace":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(AceRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "aceRequest":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(AceRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "dice":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(DiceRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "diceRequest":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(DiceRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "ice":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(IceRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "iceRequest":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(IceRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "notify":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(NotifyRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "notifyRequest":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(NotifyRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "pie":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(PieRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        case "pieRequest":
          deserialized = tree.traverse(jp.getCodec()).readValueAs(PieRequestDto.class);
          newWebhooksEventDto.setActualInstance(deserialized);
          return newWebhooksEventDto;
        default:
          log.log(
              Level.WARNING,
              String.format(
                  "Failed to lookup discriminator value `%s` for WebhooksEventDto. Possible values:"
                      + " ace aceRequest dice diceRequest ice iceRequest notify notifyRequest pie"
                      + " pieRequest",
                  discriminatorValue));
      }

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

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

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

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

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

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

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

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

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

  public WebhooksEventDto(AceRequestDto o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
  }

  public WebhooksEventDto(DiceRequestDto o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
  }

  public WebhooksEventDto(IceRequestDto o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
  }

  public WebhooksEventDto(NotifyRequestDto o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
  }

  public WebhooksEventDto(PieRequestDto o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
  }

  static {
    schemas.put("AceRequestDto", AceRequestDto.class);
    schemas.put("DiceRequestDto", DiceRequestDto.class);
    schemas.put("IceRequestDto", IceRequestDto.class);
    schemas.put("NotifyRequestDto", NotifyRequestDto.class);
    schemas.put("PieRequestDto", PieRequestDto.class);
    JSONNavigator.registerDescendants(WebhooksEventDto.class, Collections.unmodifiableMap(schemas));
    // Initialize and register the discriminator mappings.
    Map> mappings = new HashMap>();
    mappings.put("ace", AceRequestDto.class);
    mappings.put("aceRequest", AceRequestDto.class);
    mappings.put("dice", DiceRequestDto.class);
    mappings.put("diceRequest", DiceRequestDto.class);
    mappings.put("ice", IceRequestDto.class);
    mappings.put("iceRequest", IceRequestDto.class);
    mappings.put("notify", NotifyRequestDto.class);
    mappings.put("notifyRequest", NotifyRequestDto.class);
    mappings.put("pie", PieRequestDto.class);
    mappings.put("pieRequest", PieRequestDto.class);
    mappings.put("webhooksEvent", WebhooksEventDto.class);
    JSONNavigator.registerDiscriminator(WebhooksEventDto.class, "event", mappings);
  }

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

  /**
   * Set the instance that matches the oneOf child schema, check the instance parameter is valid
   * against the oneOf child schemas: AceRequestDto, DiceRequestDto, IceRequestDto,
   * NotifyRequestDto, PieRequestDto
   *
   * 

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(AceRequestDto.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } if (JSONNavigator.isInstanceOf(DiceRequestDto.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } if (JSONNavigator.isInstanceOf(IceRequestDto.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } if (JSONNavigator.isInstanceOf(NotifyRequestDto.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } if (JSONNavigator.isInstanceOf(PieRequestDto.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } throw new RuntimeException( "Invalid instance type. Must be AceRequestDto, DiceRequestDto, IceRequestDto," + " NotifyRequestDto, PieRequestDto"); } /** * Get the actual instance, which can be the following: AceRequestDto, DiceRequestDto, * IceRequestDto, NotifyRequestDto, PieRequestDto * * @return The actual instance (AceRequestDto, DiceRequestDto, IceRequestDto, NotifyRequestDto, * PieRequestDto) */ @Override public Object getActualInstance() { return super.getActualInstance(); } /** * Get the actual instance of `AceRequestDto`. If the actual instance is not `AceRequestDto`, the * ClassCastException will be thrown. * * @return The actual instance of `AceRequestDto` * @throws ClassCastException if the instance is not `AceRequestDto` */ public AceRequestDto getAceRequestDto() throws ClassCastException { return (AceRequestDto) super.getActualInstance(); } /** * Get the actual instance of `DiceRequestDto`. If the actual instance is not `DiceRequestDto`, * the ClassCastException will be thrown. * * @return The actual instance of `DiceRequestDto` * @throws ClassCastException if the instance is not `DiceRequestDto` */ public DiceRequestDto getDiceRequestDto() throws ClassCastException { return (DiceRequestDto) super.getActualInstance(); } /** * Get the actual instance of `IceRequestDto`. If the actual instance is not `IceRequestDto`, the * ClassCastException will be thrown. * * @return The actual instance of `IceRequestDto` * @throws ClassCastException if the instance is not `IceRequestDto` */ public IceRequestDto getIceRequestDto() throws ClassCastException { return (IceRequestDto) super.getActualInstance(); } /** * Get the actual instance of `NotifyRequestDto`. If the actual instance is not * `NotifyRequestDto`, the ClassCastException will be thrown. * * @return The actual instance of `NotifyRequestDto` * @throws ClassCastException if the instance is not `NotifyRequestDto` */ public NotifyRequestDto getNotifyRequestDto() throws ClassCastException { return (NotifyRequestDto) super.getActualInstance(); } /** * Get the actual instance of `PieRequestDto`. If the actual instance is not `PieRequestDto`, the * ClassCastException will be thrown. * * @return The actual instance of `PieRequestDto` * @throws ClassCastException if the instance is not `PieRequestDto` */ public PieRequestDto getPieRequestDto() throws ClassCastException { return (PieRequestDto) super.getActualInstance(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy