Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes (Numbers): Fixes for OptionalValue getter and DelegatedSerializer #114

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
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.numbers.models.v1.errors.internal.InternalErrorError;
import com.sinch.sdk.domains.numbers.models.v1.errors.internal.InternalErrorErrorImpl;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@JsonPropertyOrder({InternalErrorImpl.JSON_PROPERTY_ERROR})
@JsonFilter("uninitializedFilter")
Expand Down Expand Up @@ -48,7 +56,7 @@ public CodeEnum getCode() {
}

public OptionalValue<CodeEnum> code() {
return null != error
return null != error && error.isPresent()
? error.map(f -> CodeEnum.from(error.get().getCode().value()))
: OptionalValue.empty();
}
Expand All @@ -62,7 +70,9 @@ public String getMessage() {
}

public OptionalValue<String> message() {
return null != error ? error.map(InternalErrorError::getMessage) : OptionalValue.empty();
return null != error && error.isPresent()
? error.map(f -> ((InternalErrorErrorImpl) f).message()).orElse(OptionalValue.empty())
asein-sinch marked this conversation as resolved.
Show resolved Hide resolved
: OptionalValue.empty();
}

@JsonIgnore
Expand All @@ -74,7 +84,7 @@ public StatusEnum getStatus() {
}

public OptionalValue<StatusEnum> status() {
return null != error
return null != error && error.isPresent()
? error.map(f -> StatusEnum.from(error.get().getStatus().value()))
: OptionalValue.empty();
}
Expand All @@ -88,7 +98,9 @@ public List<Object> getDetails() {
}

public OptionalValue<List<Object>> details() {
return null != error ? error.map(InternalErrorError::getDetails) : OptionalValue.empty();
return null != error && error.isPresent()
? error.map(f -> ((InternalErrorErrorImpl) f).details()).orElse(OptionalValue.empty())
: OptionalValue.empty();
}

/** Return true if this InternalError object is equal to o. */
Expand Down Expand Up @@ -182,4 +194,37 @@ public InternalError build() {
return new InternalErrorImpl(error);
}
}

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

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

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

InternalErrorImpl.Builder builder = new InternalErrorImpl.Builder();
InternalErrorErrorImpl deserialized = jp.readValueAs(InternalErrorErrorImpl.class);
builder.setError(deserialized);
return builder.build();
}
}

public static Optional<InternalError> delegatedConverter(InternalErrorError internal) {
if (null == internal) {
return Optional.empty();
}
return Optional.of(new Builder().setError(internal).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
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.numbers.models.v1.errors.internal.InvalidArgumentError;
import com.sinch.sdk.domains.numbers.models.v1.errors.internal.InvalidArgumentErrorImpl;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@JsonPropertyOrder({InvalidArgumentImpl.JSON_PROPERTY_ERROR})
@JsonFilter("uninitializedFilter")
Expand Down Expand Up @@ -48,7 +56,7 @@ public CodeEnum getCode() {
}

public OptionalValue<CodeEnum> code() {
return null != error
return null != error && error.isPresent()
? error.map(f -> CodeEnum.from(error.get().getCode().value()))
: OptionalValue.empty();
}
Expand All @@ -62,7 +70,9 @@ public String getMessage() {
}

public OptionalValue<String> message() {
return null != error ? error.map(InvalidArgumentError::getMessage) : OptionalValue.empty();
return null != error && error.isPresent()
? error.map(f -> ((InvalidArgumentErrorImpl) f).message()).orElse(OptionalValue.empty())
: OptionalValue.empty();
}

@JsonIgnore
Expand All @@ -74,7 +84,7 @@ public StatusEnum getStatus() {
}

public OptionalValue<StatusEnum> status() {
return null != error
return null != error && error.isPresent()
? error.map(f -> StatusEnum.from(error.get().getStatus().value()))
: OptionalValue.empty();
}
Expand All @@ -88,7 +98,9 @@ public List<BadRequest> getDetails() {
}

public OptionalValue<List<BadRequest>> details() {
return null != error ? error.map(InvalidArgumentError::getDetails) : OptionalValue.empty();
return null != error && error.isPresent()
? error.map(f -> ((InvalidArgumentErrorImpl) f).details()).orElse(OptionalValue.empty())
: OptionalValue.empty();
}

/** Return true if this InvalidArgument object is equal to o. */
Expand Down Expand Up @@ -182,4 +194,37 @@ public InvalidArgument build() {
return new InvalidArgumentImpl(error);
}
}

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

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

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

InvalidArgumentImpl.Builder builder = new InvalidArgumentImpl.Builder();
InvalidArgumentErrorImpl deserialized = jp.readValueAs(InvalidArgumentErrorImpl.class);
builder.setError(deserialized);
return builder.build();
}
}

public static Optional<InvalidArgument> delegatedConverter(InvalidArgumentError internal) {
if (null == internal) {
return Optional.empty();
}
return Optional.of(new Builder().setError(internal).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
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.numbers.models.v1.errors.internal.NotFoundError;
import com.sinch.sdk.domains.numbers.models.v1.errors.internal.NotFoundErrorImpl;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@JsonPropertyOrder({NotFoundImpl.JSON_PROPERTY_ERROR})
@JsonFilter("uninitializedFilter")
Expand Down Expand Up @@ -48,7 +56,7 @@ public CodeEnum getCode() {
}

public OptionalValue<CodeEnum> code() {
return null != error
return null != error && error.isPresent()
? error.map(f -> CodeEnum.from(error.get().getCode().value()))
: OptionalValue.empty();
}
Expand All @@ -62,7 +70,9 @@ public String getMessage() {
}

public OptionalValue<String> message() {
return null != error ? error.map(NotFoundError::getMessage) : OptionalValue.empty();
return null != error && error.isPresent()
? error.map(f -> ((NotFoundErrorImpl) f).message()).orElse(OptionalValue.empty())
: OptionalValue.empty();
}

@JsonIgnore
Expand All @@ -74,7 +84,7 @@ public StatusEnum getStatus() {
}

public OptionalValue<StatusEnum> status() {
return null != error
return null != error && error.isPresent()
? error.map(f -> StatusEnum.from(error.get().getStatus().value()))
: OptionalValue.empty();
}
Expand All @@ -88,7 +98,9 @@ public List<Object> getDetails() {
}

public OptionalValue<List<Object>> details() {
return null != error ? error.map(NotFoundError::getDetails) : OptionalValue.empty();
return null != error && error.isPresent()
? error.map(f -> ((NotFoundErrorImpl) f).details()).orElse(OptionalValue.empty())
: OptionalValue.empty();
}

/** Return true if this NotFound object is equal to o. */
Expand Down Expand Up @@ -181,4 +193,36 @@ public NotFound build() {
return new NotFoundImpl(error);
}
}

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

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

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

NotFoundImpl.Builder builder = new NotFoundImpl.Builder();
NotFoundErrorImpl deserialized = jp.readValueAs(NotFoundErrorImpl.class);
builder.setError(deserialized);
return builder.build();
}
}

public static Optional<NotFound> delegatedConverter(NotFoundError internal) {
if (null == internal) {
return Optional.empty();
}
return Optional.of(new Builder().setError(internal).build());
}
}
Loading