Skip to content
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 @@ -52,7 +52,9 @@ public class DidwwResourceConverter {
public static ObjectMapper createObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new EnumModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/didww/sdk/converter/EnumModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.didww.sdk.converter;

import com.didww.sdk.resource.enums.IntEnum;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.module.SimpleDeserializers;
import com.fasterxml.jackson.databind.module.SimpleModule;

import java.io.IOException;

public class EnumModule extends SimpleModule {

public EnumModule() {
super("EnumModule");
setDeserializers(new SimpleDeserializers() {
@Override
@SuppressWarnings("unchecked")
public JsonDeserializer<?> findEnumDeserializer(Class<?> type,
DeserializationConfig config, BeanDescription beanDesc) {
if (IntEnum.class.isAssignableFrom(type)) {
return new IntEnumDeserializer((Class<? extends Enum<?>>) type);
}
return null;
}
});
}

private static class IntEnumDeserializer extends JsonDeserializer<Enum<?>> {
private final Class<? extends Enum<?>> enumType;

IntEnumDeserializer(Class<? extends Enum<?>> enumType) {
this.enumType = enumType;
}

@Override
public Enum<?> deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
int value = p.getIntValue();
for (Enum<?> constant : enumType.getEnumConstants()) {
if (((IntEnum) constant).getValue() == value) {
return constant;
}
}
if (ctx.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
throw new IllegalArgumentException("Unknown " + enumType.getSimpleName() + ": " + value);
}
}
}
12 changes: 7 additions & 5 deletions src/main/java/com/didww/sdk/resource/AddressVerification.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.didww.sdk.resource;

import com.didww.sdk.resource.enums.AddressVerificationStatus;
import com.didww.sdk.resource.enums.CallbackMethod;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.jasminb.jsonapi.annotations.Relationship;
import com.github.jasminb.jsonapi.annotations.Type;
Expand All @@ -17,10 +19,10 @@ public class AddressVerification extends BaseResource {
private String callbackUrl;

@JsonProperty("callback_method")
private String callbackMethod;
private CallbackMethod callbackMethod;

@JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY)
private String status;
private AddressVerificationStatus status;

@JsonProperty(value = "reject_reasons", access = JsonProperty.Access.WRITE_ONLY)
private List<String> rejectReasons;
Expand Down Expand Up @@ -50,15 +52,15 @@ public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}

public String getCallbackMethod() {
public CallbackMethod getCallbackMethod() {
return callbackMethod;
}

public void setCallbackMethod(String callbackMethod) {
public void setCallbackMethod(CallbackMethod callbackMethod) {
this.callbackMethod = callbackMethod;
}

public String getStatus() {
public AddressVerificationStatus getStatus() {
return status;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/didww/sdk/resource/DidGroup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.didww.sdk.resource;

import com.didww.sdk.resource.enums.Feature;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.jasminb.jsonapi.annotations.Relationship;
import com.github.jasminb.jsonapi.annotations.Type;
Expand All @@ -16,7 +17,7 @@ public class DidGroup extends BaseResource {
private String prefix;

@JsonProperty("features")
private List<String> features;
private List<Feature> features;

@JsonProperty("is_metered")
private Boolean isMetered;
Expand Down Expand Up @@ -47,7 +48,7 @@ public String getPrefix() {
return prefix;
}

public List<String> getFeatures() {
public List<Feature> getFeatures() {
return features;
}

Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/didww/sdk/resource/Export.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.didww.sdk.resource;

import com.didww.sdk.resource.enums.CallbackMethod;
import com.didww.sdk.resource.enums.ExportStatus;
import com.didww.sdk.resource.enums.ExportType;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.jasminb.jsonapi.annotations.Type;

Expand All @@ -10,7 +13,7 @@
public class Export extends BaseResource {

@JsonProperty("export_type")
private String exportType;
private ExportType exportType;

@JsonProperty(value = "url", access = JsonProperty.Access.WRITE_ONLY)
private String url;
Expand All @@ -19,22 +22,22 @@ public class Export extends BaseResource {
private String callbackUrl;

@JsonProperty("callback_method")
private String callbackMethod;
private CallbackMethod callbackMethod;

@JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY)
private String status;
private ExportStatus status;

@JsonProperty("filters")
private Map<String, Object> filters;

@JsonProperty(value = "created_at", access = JsonProperty.Access.WRITE_ONLY)
private OffsetDateTime createdAt;

public String getExportType() {
public ExportType getExportType() {
return exportType;
}

public void setExportType(String exportType) {
public void setExportType(ExportType exportType) {
this.exportType = exportType;
}

Expand All @@ -50,15 +53,15 @@ public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}

public String getCallbackMethod() {
public CallbackMethod getCallbackMethod() {
return callbackMethod;
}

public void setCallbackMethod(String callbackMethod) {
public void setCallbackMethod(CallbackMethod callbackMethod) {
this.callbackMethod = callbackMethod;
}

public String getStatus() {
public ExportStatus getStatus() {
return status;
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/didww/sdk/resource/Identity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.didww.sdk.resource;

import com.didww.sdk.resource.enums.IdentityType;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.jasminb.jsonapi.annotations.Relationship;
import com.github.jasminb.jsonapi.annotations.Type;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class Identity extends BaseResource {
private String personalTaxId;

@JsonProperty("identity_type")
private String identityType;
private IdentityType identityType;

@JsonProperty("external_reference_id")
private String externalReferenceId;
Expand Down Expand Up @@ -145,11 +146,11 @@ public void setPersonalTaxId(String personalTaxId) {
this.personalTaxId = personalTaxId;
}

public String getIdentityType() {
public IdentityType getIdentityType() {
return identityType;
}

public void setIdentityType(String identityType) {
public void setIdentityType(IdentityType identityType) {
this.identityType = identityType;
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/didww/sdk/resource/Order.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.didww.sdk.resource;

import com.didww.sdk.resource.enums.CallbackMethod;
import com.didww.sdk.resource.enums.OrderStatus;
import com.didww.sdk.converter.OrderItemDeserializer;
import com.didww.sdk.converter.OrderItemSerializer;
import com.didww.sdk.resource.orderitem.OrderItem;
Expand All @@ -18,7 +20,7 @@ public class Order extends BaseResource {
private Double amount;

@JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY)
private String status;
private OrderStatus status;

@JsonProperty(value = "description", access = JsonProperty.Access.WRITE_ONLY)
private String description;
Expand All @@ -33,7 +35,7 @@ public class Order extends BaseResource {
private String callbackUrl;

@JsonProperty("callback_method")
private String callbackMethod;
private CallbackMethod callbackMethod;

@JsonProperty("allow_back_ordering")
private Boolean allowBackOrdering;
Expand All @@ -47,7 +49,7 @@ public Double getAmount() {
return amount;
}

public String getStatus() {
public OrderStatus getStatus() {
return status;
}

Expand All @@ -71,11 +73,11 @@ public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}

public String getCallbackMethod() {
public CallbackMethod getCallbackMethod() {
return callbackMethod;
}

public void setCallbackMethod(String callbackMethod) {
public void setCallbackMethod(CallbackMethod callbackMethod) {
this.callbackMethod = callbackMethod;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/didww/sdk/resource/Requirement.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.didww.sdk.resource;

import com.didww.sdk.resource.enums.IdentityType;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.jasminb.jsonapi.annotations.Relationship;
import com.github.jasminb.jsonapi.annotations.Type;
Expand All @@ -10,7 +11,7 @@
public class Requirement extends BaseResource {

@JsonProperty("identity_type")
private String identityType;
private IdentityType identityType;

@JsonProperty("personal_area_level")
private String personalAreaLevel;
Expand Down Expand Up @@ -69,7 +70,7 @@ public class Requirement extends BaseResource {
@Relationship("address_proof_types")
private List<ProofType> addressProofTypes;

public String getIdentityType() {
public IdentityType getIdentityType() {
return identityType;
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/didww/sdk/resource/VoiceInTrunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.didww.sdk.converter.TrunkConfigurationDeserializer;
import com.didww.sdk.converter.TrunkConfigurationSerializer;
import com.didww.sdk.resource.configuration.TrunkConfiguration;
import com.didww.sdk.resource.enums.CliFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand All @@ -24,7 +25,7 @@ public class VoiceInTrunk extends BaseResource {
private Integer weight;

@JsonProperty("cli_format")
private String cliFormat;
private CliFormat cliFormat;

@JsonProperty("cli_prefix")
private String cliPrefix;
Expand Down Expand Up @@ -76,11 +77,11 @@ public void setWeight(Integer weight) {
this.weight = weight;
}

public String getCliFormat() {
public CliFormat getCliFormat() {
return cliFormat;
}

public void setCliFormat(String cliFormat) {
public void setCliFormat(CliFormat cliFormat) {
this.cliFormat = cliFormat;
}

Expand Down
Loading