diff --git a/src/main/java/com/whatsapp/api/domain/messages/type/MessageType.java b/src/main/java/com/whatsapp/api/domain/messages/type/MessageType.java index 435ffd8fc..2e83861fa 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/type/MessageType.java +++ b/src/main/java/com/whatsapp/api/domain/messages/type/MessageType.java @@ -1,6 +1,7 @@ package com.whatsapp.api.domain.messages.type; //TODO: implementar mais tipos de mensagens. Não está completo. +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; import com.fasterxml.jackson.annotation.JsonValue; /** @@ -78,7 +79,7 @@ public enum MessageType { /** * Unknown message type. */ - UNKNOWN("unknown"), // + @JsonEnumDefaultValue UNKNOWN( "unknown"), // /** * Video message type. */ diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Change.java b/src/main/java/com/whatsapp/api/domain/webhook/Change.java index b08bc45de..db95371a1 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Change.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Change.java @@ -1,9 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.webhook.type.FieldType; +import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE; + /** * Changes that triggered the Webhooks call. * @@ -11,6 +14,7 @@ * @param value Contains the type of notification you are getting on that Webhook. Currently, the only option for this API is “messages”. */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE) public record Change( /* Contains the type of notification you are getting on that Webhook. Currently, the only option for this API is “messages”. diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Message.java b/src/main/java/com/whatsapp/api/domain/webhook/Message.java index 8c4041b78..c321e2ec1 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Message.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Message.java @@ -1,11 +1,14 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.messages.type.MessageType; import java.util.List; +import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE; + /** * The type Message. * @@ -31,6 +34,7 @@ * @param document A media object with the document information. Added to Webhook if type is document. See {@link Document} */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE) public record Message( @JsonProperty("reaction") Reaction reaction, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/RestrictionInfo.java b/src/main/java/com/whatsapp/api/domain/webhook/RestrictionInfo.java index 226854119..46f23b365 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/RestrictionInfo.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/RestrictionInfo.java @@ -1,13 +1,17 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.webhook.type.RestrictionType; +import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE; + /** * The type Restriction info. */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE) public record RestrictionInfo( @JsonProperty("restriction_type") RestrictionType restrictionType, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Status.java b/src/main/java/com/whatsapp/api/domain/webhook/Status.java index 9f997c46d..0779f0904 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Status.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Status.java @@ -1,11 +1,14 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.webhook.type.MessageStatus; import java.util.List; +import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE; + /** * The type Status. * @@ -18,6 +21,7 @@ * @param errors The errors object in webhooks triggered by v16.0+ request errors now include message and error_data.details properties, and title values have changed for multiple error codes. */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE) public record Status( @JsonProperty("id") String id, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Value.java b/src/main/java/com/whatsapp/api/domain/webhook/Value.java index 376d94e10..4e071b004 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Value.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Value.java @@ -1,11 +1,14 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.webhook.type.EventType; import java.util.List; +import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE; + /** * The type Value. * @@ -26,6 +29,7 @@ * @param requestedVerifiedName This field displays the name that was sent to be verified. */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE) public record Value( @JsonProperty("metadata") Metadata metadata, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/type/EventType.java b/src/main/java/com/whatsapp/api/domain/webhook/type/EventType.java index 1742b74fd..7e09006ce 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/type/EventType.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/type/EventType.java @@ -1,5 +1,7 @@ package com.whatsapp.api.domain.webhook.type; +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; + /** * Used when an event happened in a specific WABA. * See Webhooks Components @@ -81,6 +83,12 @@ public enum EventType { /** * Pin changed event type. */ - PIN_CHANGED + PIN_CHANGED, + + /** + * Fallback value. + */ + @JsonEnumDefaultValue + UNKNOWN; } diff --git a/src/main/java/com/whatsapp/api/domain/webhook/type/FieldType.java b/src/main/java/com/whatsapp/api/domain/webhook/type/FieldType.java index 97e443598..766f4dcc4 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/type/FieldType.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/type/FieldType.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook.type; +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; import com.fasterxml.jackson.annotation.JsonValue; @@ -38,7 +39,13 @@ public enum FieldType { *
  • the two-step verification code is updated
  • * */ - security("security"); + SECURITY( "security"), + + /** + * Fallback value. + */ + @JsonEnumDefaultValue + UNKNOWN( "unknown"); private final String value; diff --git a/src/main/java/com/whatsapp/api/domain/webhook/type/MessageStatus.java b/src/main/java/com/whatsapp/api/domain/webhook/type/MessageStatus.java index 0af9014ad..d79d60836 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/type/MessageStatus.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/type/MessageStatus.java @@ -1,6 +1,7 @@ package com.whatsapp.api.domain.webhook.type; +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; import com.fasterxml.jackson.annotation.JsonValue; /** @@ -21,13 +22,18 @@ public enum MessageStatus { READ("read"), /** - * Message failed to send.(Red error triangle) + * Message failed to send. (Red error triangle) */ FAILED("failed"), /** - * Message deleted by the user. ( Message is replaced in WhatsApp mobile with the note "This message was deleted".) + * Message deleted by the user. (Message is replaced in WhatsApp mobile with the note "This message was deleted".) */ - DELETED("deleted"); + DELETED("deleted"), + + /** + * Fallback value. + */ + @JsonEnumDefaultValue UNKNOWN( "unknown"); private final String value; diff --git a/src/main/java/com/whatsapp/api/domain/webhook/type/RestrictionType.java b/src/main/java/com/whatsapp/api/domain/webhook/type/RestrictionType.java index a72f5fb2e..19a037bb1 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/type/RestrictionType.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/type/RestrictionType.java @@ -1,5 +1,7 @@ package com.whatsapp.api.domain.webhook.type; +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; + /** * The enum Restriction type. */ @@ -15,5 +17,11 @@ public enum RestrictionType { /** * Restricted customer initiated messaging restriction type. */ - RESTRICTED_CUSTOMER_INITIATED_MESSAGING + RESTRICTED_CUSTOMER_INITIATED_MESSAGING, + + /** + * Fallback value. + */ + @JsonEnumDefaultValue + UNKNOWN; }