Skip to content

Commit

Permalink
Merge pull request #115 from sinch/verification-guard-null-DelegatedS…
Browse files Browse the repository at this point in the history
…erializer

fixes (Verification): Fixes for OptionalValue getter and DelegatedSerialize
  • Loading branch information
JPPortier authored Aug 12, 2024
2 parents 515d6a1 + 8cdeef1 commit b958435
Show file tree
Hide file tree
Showing 12 changed files with 675 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestFlashCallOptions;
import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestFlashCallOptionsImpl;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;

@JsonPropertyOrder({
VerificationReportRequestFlashCallImpl.JSON_PROPERTY_METHOD,
Expand Down Expand Up @@ -69,8 +78,10 @@ public String getCli() {
}

public OptionalValue<String> cli() {
return null != flashCall
? flashCall.map(VerificationReportRequestFlashCallOptions::getCli)
return null != flashCall && flashCall.isPresent()
? flashCall
.map(f -> ((VerificationReportRequestFlashCallOptionsImpl) f).cli())
.orElse(OptionalValue.empty())
: OptionalValue.empty();
}

Expand Down Expand Up @@ -148,4 +159,45 @@ public VerificationReportRequestFlashCall build() {
return new VerificationReportRequestFlashCallImpl(method, flashCall);
}
}

public static class DelegatedSerializer
extends JsonSerializer<OptionalValue<VerificationReportRequestFlashCall>> {
@Override
public void serialize(
OptionalValue<VerificationReportRequestFlashCall> value,
JsonGenerator jgen,
SerializerProvider provider)
throws IOException {

if (!value.isPresent()) {
return;
}
VerificationReportRequestFlashCallImpl impl =
(VerificationReportRequestFlashCallImpl) value.get();
jgen.writeObject(null != impl ? impl.getFlashCall() : null);
}
}

public static class DelegatedDeSerializer
extends JsonDeserializer<VerificationReportRequestFlashCall> {
@Override
public VerificationReportRequestFlashCall deserialize(
JsonParser jp, DeserializationContext ctxt) throws IOException {

VerificationReportRequestFlashCallImpl.Builder builder =
new VerificationReportRequestFlashCallImpl.Builder();
VerificationReportRequestFlashCallOptionsImpl deserialized =
jp.readValueAs(VerificationReportRequestFlashCallOptionsImpl.class);
builder.setFlashCall(deserialized);
return builder.build();
}
}

public static Optional<VerificationReportRequestFlashCall> delegatedConverter(
VerificationReportRequestFlashCallOptions internal) {
if (null == internal) {
return Optional.empty();
}
return Optional.of(new Builder().setFlashCall(internal).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestPhoneCallOptions;
import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestPhoneCallOptionsImpl;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;

@JsonPropertyOrder({
VerificationReportRequestPhoneCallImpl.JSON_PROPERTY_METHOD,
Expand Down Expand Up @@ -69,8 +78,10 @@ public String getCode() {
}

public OptionalValue<String> code() {
return null != callout
? callout.map(VerificationReportRequestPhoneCallOptions::getCode)
return null != callout && callout.isPresent()
? callout
.map(f -> ((VerificationReportRequestPhoneCallOptionsImpl) f).code())
.orElse(OptionalValue.empty())
: OptionalValue.empty();
}

Expand Down Expand Up @@ -148,4 +159,45 @@ public VerificationReportRequestPhoneCall build() {
return new VerificationReportRequestPhoneCallImpl(method, callout);
}
}

public static class DelegatedSerializer
extends JsonSerializer<OptionalValue<VerificationReportRequestPhoneCall>> {
@Override
public void serialize(
OptionalValue<VerificationReportRequestPhoneCall> value,
JsonGenerator jgen,
SerializerProvider provider)
throws IOException {

if (!value.isPresent()) {
return;
}
VerificationReportRequestPhoneCallImpl impl =
(VerificationReportRequestPhoneCallImpl) value.get();
jgen.writeObject(null != impl ? impl.getCallout() : null);
}
}

public static class DelegatedDeSerializer
extends JsonDeserializer<VerificationReportRequestPhoneCall> {
@Override
public VerificationReportRequestPhoneCall deserialize(
JsonParser jp, DeserializationContext ctxt) throws IOException {

VerificationReportRequestPhoneCallImpl.Builder builder =
new VerificationReportRequestPhoneCallImpl.Builder();
VerificationReportRequestPhoneCallOptionsImpl deserialized =
jp.readValueAs(VerificationReportRequestPhoneCallOptionsImpl.class);
builder.setCallout(deserialized);
return builder.build();
}
}

public static Optional<VerificationReportRequestPhoneCall> delegatedConverter(
VerificationReportRequestPhoneCallOptions internal) {
if (null == internal) {
return Optional.empty();
}
return Optional.of(new Builder().setCallout(internal).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestSmsOptions;
import com.sinch.sdk.domains.verification.models.v1.report.request.internal.VerificationReportRequestSmsOptionsImpl;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;

@JsonPropertyOrder({
VerificationReportRequestSmsImpl.JSON_PROPERTY_METHOD,
Expand Down Expand Up @@ -68,8 +77,9 @@ public String getCode() {
}

public OptionalValue<String> code() {
return null != sms
? sms.map(VerificationReportRequestSmsOptions::getCode)
return null != sms && sms.isPresent()
? sms.map(f -> ((VerificationReportRequestSmsOptionsImpl) f).code())
.orElse(OptionalValue.empty())
: OptionalValue.empty();
}

Expand All @@ -82,8 +92,9 @@ public String getCli() {
}

public OptionalValue<String> cli() {
return null != sms
? sms.map(VerificationReportRequestSmsOptions::getCli)
return null != sms && sms.isPresent()
? sms.map(f -> ((VerificationReportRequestSmsOptionsImpl) f).cli())
.orElse(OptionalValue.empty())
: OptionalValue.empty();
}

Expand Down Expand Up @@ -167,4 +178,43 @@ public VerificationReportRequestSms build() {
return new VerificationReportRequestSmsImpl(method, sms);
}
}

public static class DelegatedSerializer
extends JsonSerializer<OptionalValue<VerificationReportRequestSms>> {
@Override
public void serialize(
OptionalValue<VerificationReportRequestSms> value,
JsonGenerator jgen,
SerializerProvider provider)
throws IOException {

if (!value.isPresent()) {
return;
}
VerificationReportRequestSmsImpl impl = (VerificationReportRequestSmsImpl) value.get();
jgen.writeObject(null != impl ? impl.getSms() : null);
}
}

public static class DelegatedDeSerializer extends JsonDeserializer<VerificationReportRequestSms> {
@Override
public VerificationReportRequestSms deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException {

VerificationReportRequestSmsImpl.Builder builder =
new VerificationReportRequestSmsImpl.Builder();
VerificationReportRequestSmsOptionsImpl deserialized =
jp.readValueAs(VerificationReportRequestSmsOptionsImpl.class);
builder.setSms(deserialized);
return builder.build();
}
}

public static Optional<VerificationReportRequestSms> delegatedConverter(
VerificationReportRequestSmsOptions internal) {
if (null == internal) {
return Optional.empty();
}
return Optional.of(new Builder().setSms(internal).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.domains.verification.models.v1.Identity;
import com.sinch.sdk.domains.verification.models.v1.VerificationMethod;
import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartFlashCallOptions;
import com.sinch.sdk.domains.verification.models.v1.start.request.internal.VerificationStartFlashCallOptionsImpl;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;

@JsonPropertyOrder({
VerificationStartRequestFlashCallImpl.JSON_PROPERTY_IDENTITY,
Expand Down Expand Up @@ -127,8 +136,10 @@ public Integer getDialTimeout() {
}

public OptionalValue<Integer> dialTimeout() {
return null != flashCallOptions
? flashCallOptions.map(VerificationStartFlashCallOptions::getDialTimeout)
return null != flashCallOptions && flashCallOptions.isPresent()
? flashCallOptions
.map(f -> ((VerificationStartFlashCallOptionsImpl) f).dialTimeout())
.orElse(OptionalValue.empty())
: OptionalValue.empty();
}

Expand Down Expand Up @@ -235,4 +246,45 @@ public VerificationStartRequestFlashCall build() {
identity, method, reference, custom, flashCallOptions);
}
}

public static class DelegatedSerializer
extends JsonSerializer<OptionalValue<VerificationStartRequestFlashCall>> {
@Override
public void serialize(
OptionalValue<VerificationStartRequestFlashCall> value,
JsonGenerator jgen,
SerializerProvider provider)
throws IOException {

if (!value.isPresent()) {
return;
}
VerificationStartRequestFlashCallImpl impl =
(VerificationStartRequestFlashCallImpl) value.get();
jgen.writeObject(null != impl ? impl.getFlashCallOptions() : null);
}
}

public static class DelegatedDeSerializer
extends JsonDeserializer<VerificationStartRequestFlashCall> {
@Override
public VerificationStartRequestFlashCall deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException {

VerificationStartRequestFlashCallImpl.Builder builder =
new VerificationStartRequestFlashCallImpl.Builder();
VerificationStartFlashCallOptionsImpl deserialized =
jp.readValueAs(VerificationStartFlashCallOptionsImpl.class);
builder.setFlashCallOptions(deserialized);
return builder.build();
}
}

public static Optional<VerificationStartRequestFlashCall> delegatedConverter(
VerificationStartFlashCallOptions internal) {
if (null == internal) {
return Optional.empty();
}
return Optional.of(new Builder().setFlashCallOptions(internal).build());
}
}
Loading

0 comments on commit b958435

Please sign in to comment.