From b1b841bc395846b35c3efc2d8e26f8de72bea2e1 Mon Sep 17 00:00:00 2001 From: Stein Desmet Date: Tue, 2 Jan 2024 13:36:01 +0100 Subject: [PATCH 1/6] Specify our own Jackson version --- pom.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pom.xml b/pom.xml index c4a573c41..3d5899aae 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ 5.2.0 5.10.0 5.0.0-alpha.11 + 2.16.0 @@ -61,6 +62,23 @@ okhttp ${com.squareup.okhttp3.version} + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + org.junit.jupiter From 8eb70e438c7d7a11d7dcea6fdb916d1bcdb0847f Mon Sep 17 00:00:00 2001 From: Stein Desmet Date: Tue, 2 Jan 2024 13:47:58 +0100 Subject: [PATCH 2/6] Ignore unknown properties on webhooks Prevent webhook deserialization failing when Meta adds a field. Fixes Bindambc/whatsapp-business-java-api#127 --- src/main/java/com/whatsapp/api/domain/webhook/Address.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Audio.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/BanInfo.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Button.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/ButtonReply.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Change.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Contact.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Context.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Conversation.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/DisableInfo.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Document.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Email.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Entry.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Error.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/ErrorData.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Image.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Interactive.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/ListReply.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Location.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Message.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Metadata.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Name.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Order.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Org.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Origin.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Phone.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Pricing.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Product.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Profile.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Reaction.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Referral.java | 2 ++ .../java/com/whatsapp/api/domain/webhook/ReferredProduct.java | 2 ++ .../java/com/whatsapp/api/domain/webhook/RestrictionInfo.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Status.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Sticker.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/System.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Text.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Value.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/Video.java | 2 ++ src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java | 2 ++ 40 files changed, 80 insertions(+) diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Address.java b/src/main/java/com/whatsapp/api/domain/webhook/Address.java index 601ccf2ae..e6db54ad9 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Address.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Address.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Address. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Address( @JsonProperty("zip") String zip, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Audio.java b/src/main/java/com/whatsapp/api/domain/webhook/Audio.java index d3ee2ad51..b624b5f3a 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Audio.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Audio.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -9,6 +10,7 @@ * @param mimeType The mime type of the media. The caption that describes the media. * @param id The ID of the medi */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Audio( @JsonProperty("mime_type") String mimeType, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/BanInfo.java b/src/main/java/com/whatsapp/api/domain/webhook/BanInfo.java index 29f3cb952..5443120f1 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/BanInfo.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/BanInfo.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Ban info. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record BanInfo(@JsonProperty("waba_ban_state") String wabaBanState, @JsonProperty("waba_ban_date") String wabaBanDate diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Button.java b/src/main/java/com/whatsapp/api/domain/webhook/Button.java index bc86de3cd..5abd0474a 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Button.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Button.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -8,6 +9,7 @@ * @param payload The developer-defined payload for the button when a business account sends interactive messages. * @param text The button text */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Button( @JsonProperty("payload") String payload, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/ButtonReply.java b/src/main/java/com/whatsapp/api/domain/webhook/ButtonReply.java index 3d73782de..c6edb79aa 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/ButtonReply.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/ButtonReply.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -8,6 +9,7 @@ * @param id The unique identifier of the button. * @param title The title of the button. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record ButtonReply( @JsonProperty("id") 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 8f4de14f6..b08bc45de 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Change.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Change.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.webhook.type.FieldType; @@ -9,6 +10,7 @@ * @param field A value object. Contains details of the changes related to the specified field. * @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) 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/Contact.java b/src/main/java/com/whatsapp/api/domain/webhook/Contact.java index 79e6b83bf..bc4632809 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Contact.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Contact.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; @@ -10,6 +11,7 @@ * @param profile The {@link Profile} object. * @param waId The WhatsApp ID of the customer. You can send messages using this wa_id. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Contact( @JsonProperty("profile") Profile profile, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Context.java b/src/main/java/com/whatsapp/api/domain/webhook/Context.java index 5f7b80fbd..8373d957a 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Context.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Context.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -11,6 +12,7 @@ * @param forwarded Added to Webhooks if message was forwarded. Set to true if the received message has been forwarded. * @param frequentlyForwarded Added to Webhooks if message has been frequently forwarded. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Context( @JsonProperty("from") String from, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Conversation.java b/src/main/java/com/whatsapp/api/domain/webhook/Conversation.java index c9f3ae20f..558bd561c 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Conversation.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Conversation.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -9,6 +10,7 @@ * @param origin Describes where the conversation originated from. See {@link Origin} object for more information. * @param id The ID of the conversation the given status notification belongs to. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Conversation( @JsonProperty("expiration_timestamp") String expirationTimestamp, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/DisableInfo.java b/src/main/java/com/whatsapp/api/domain/webhook/DisableInfo.java index 1bf2a18b0..7de81b45e 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/DisableInfo.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/DisableInfo.java @@ -1,9 +1,11 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Disable info. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record DisableInfo(@JsonProperty("disable_date") String disableDate) { } diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Document.java b/src/main/java/com/whatsapp/api/domain/webhook/Document.java index c68ac0f43..644d73584 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Document.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Document.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -11,6 +12,7 @@ * @param id ID for the document * @param caption Caption for the document, if provided */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Document( @JsonProperty("filename") String filename, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Email.java b/src/main/java/com/whatsapp/api/domain/webhook/Email.java index f99837b32..216ddf50f 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Email.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Email.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Email. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Email( @JsonProperty("type") diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Entry.java b/src/main/java/com/whatsapp/api/domain/webhook/Entry.java index 2e2424ca9..d8c539809 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Entry.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Entry.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; @@ -11,6 +12,7 @@ * @param id The ID of Whatsapp Business Accounts this Webhook belongs to. * @param time Time for the entry. (WhatsApp Business Management API) */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Entry( /* diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Error.java b/src/main/java/com/whatsapp/api/domain/webhook/Error.java index daa245822..72775dc7e 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Error.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Error.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Error. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Error( @JsonProperty("code") diff --git a/src/main/java/com/whatsapp/api/domain/webhook/ErrorData.java b/src/main/java/com/whatsapp/api/domain/webhook/ErrorData.java index 950b76ef7..9c0fa94fe 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/ErrorData.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/ErrorData.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Error data. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record ErrorData( @JsonProperty("details") diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Image.java b/src/main/java/com/whatsapp/api/domain/webhook/Image.java index 388fd4ebd..df053009d 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Image.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Image.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -10,6 +11,7 @@ * @param caption Added to Webhooks if it has been previously specified. The caption that describes the media. * @param id The ID of the medi */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Image( @JsonProperty("sha256") String sha256, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Interactive.java b/src/main/java/com/whatsapp/api/domain/webhook/Interactive.java index 0d7f7438d..d07907d57 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Interactive.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Interactive.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -9,6 +10,7 @@ * @param type Contains the type of interactive object. Supported options are:
  • button_reply: for responses of Reply Buttons.
  • list_reply: for responses to List Messages and other interactive objects.
* @param buttonReply Used on Webhooks related to Reply Buttons. Contains a {@link ButtonReply} reply object. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Interactive( @JsonProperty("list_reply") ListReply listReply, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/ListReply.java b/src/main/java/com/whatsapp/api/domain/webhook/ListReply.java index 91397b43d..01b00bf07 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/ListReply.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/ListReply.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -9,6 +10,7 @@ * @param id The unique identifier (ID) of the selected row. * @param title The title of the selected row. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record ListReply( @JsonProperty("description") diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Location.java b/src/main/java/com/whatsapp/api/domain/webhook/Location.java index c945f25c2..89e863354 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Location.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Location.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Location. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Location( @JsonProperty("address") String address, 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 419c63b7d..8c4041b78 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Message.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Message.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.messages.type.MessageType; @@ -29,6 +30,7 @@ * @param audio A media object with the audio information. Added to Webhook if type is audio (including voice messages). See {@link Audio} * @param document A media object with the document information. Added to Webhook if type is document. See {@link Document} */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Message( @JsonProperty("reaction") Reaction reaction, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Metadata.java b/src/main/java/com/whatsapp/api/domain/webhook/Metadata.java index 35d6449b1..60e1e1689 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Metadata.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Metadata.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -8,6 +9,7 @@ * @param phoneNumberId The ID of the phone number receiving the Webhooks. You can use this phone_number_id to send messages back to customers. * @param displayPhoneNumber The phone number of the business account that is receiving the Webhooks. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Metadata( /* The ID of the phone number receiving the Webhooks. You can use this phone_number_id to send messages back to customers. diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Name.java b/src/main/java/com/whatsapp/api/domain/webhook/Name.java index 291f998b9..15c659ad0 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Name.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Name.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Name. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Name( @JsonProperty("prefix") String prefix, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Order.java b/src/main/java/com/whatsapp/api/domain/webhook/Order.java index 381622e17..b1f7764b4 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Order.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Order.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; @@ -7,6 +8,7 @@ /** * The type Order. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Order( @JsonProperty("catalog_id") String catalogId, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Org.java b/src/main/java/com/whatsapp/api/domain/webhook/Org.java index f31ad9086..fa271fce3 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Org.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Org.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Org. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Org( @JsonProperty("company") String company, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Origin.java b/src/main/java/com/whatsapp/api/domain/webhook/Origin.java index 360946ac0..cc302c3ee 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Origin.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Origin.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -7,6 +8,7 @@ * * @param type Indicates where a conversation has started. This can also be referred to as a conversation entry point. Currently, the available options are:
  • business_initiated: indicates that the conversation started by a business sending the first message to a user. This applies any time it has been more than 24 hours since the last user message.
  • user_initiated: indicates that the conversation started by a business replying to a user message. This applies only when the business reply is within 24 hours of the last user message.
  • referral_conversion: indicates that the conversation originated from a free entry point. These conversations are always user-initiated.
*/ +@JsonIgnoreProperties(ignoreUnknown = true) public record Origin( @JsonProperty("type") String type diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Phone.java b/src/main/java/com/whatsapp/api/domain/webhook/Phone.java index aa25bd9ac..e2658e7ff 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Phone.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Phone.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Phone. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Phone( @JsonProperty("phone") String phone, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Pricing.java b/src/main/java/com/whatsapp/api/domain/webhook/Pricing.java index 6a5e2d9e3..05ceeb5e6 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Pricing.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Pricing.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -7,6 +8,7 @@ * * @param pricingModel Type of pricing model being used. Current supported values are:
  • "CBP" (conversation-based pricing): See Conversation-Based Pricing for rates based on recipient country.
  • "NBP" (notification-based pricing): Notifications are also known as Template Messages (click here for details on pricing).
This pricing model will be deprecated in a future release early 2022. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Pricing( @JsonProperty("pricing_model") String pricingModel, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Product.java b/src/main/java/com/whatsapp/api/domain/webhook/Product.java index 431487e47..b00da6b3b 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Product.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Product.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Product. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Product( @JsonProperty("quantity") String quantity, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Profile.java b/src/main/java/com/whatsapp/api/domain/webhook/Profile.java index 4a9988914..8d24e10ce 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Profile.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Profile.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -7,6 +8,7 @@ * * @param name Specifies the sender's profile name. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Profile( @JsonProperty("name") String name diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Reaction.java b/src/main/java/com/whatsapp/api/domain/webhook/Reaction.java index 31173d715..ffeaa7059 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Reaction.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Reaction.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -8,6 +9,7 @@ * @param emoji The emoji used for the reaction. * @param messageId Specifies the wamid of the message received that contained the reaction. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Reaction( @JsonProperty("emoji") String emoji, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Referral.java b/src/main/java/com/whatsapp/api/domain/webhook/Referral.java index 3d023a30a..81d8ba8a0 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Referral.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Referral.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -15,6 +16,7 @@ * @param headline Specifies the headline used in the ad or post that generated the message. * @param sourceUrl Specifies the URL that leads to the ad or post clicked by the user. Opening this URL takes you to the ad viewed by your user. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Referral( @JsonProperty("video_url") String videoUrl, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/ReferredProduct.java b/src/main/java/com/whatsapp/api/domain/webhook/ReferredProduct.java index 0962d7af4..f6e29a493 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/ReferredProduct.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/ReferredProduct.java @@ -1,10 +1,12 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** * The type Referred product. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record ReferredProduct( @JsonProperty("catalog_id") String catalogId, 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 104e7518a..226854119 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/RestrictionInfo.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/RestrictionInfo.java @@ -1,11 +1,13 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.webhook.type.RestrictionType; /** * The type Restriction info. */ +@JsonIgnoreProperties(ignoreUnknown = true) 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 b173c5035..9f997c46d 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Status.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Status.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.webhook.type.MessageStatus; @@ -16,6 +17,7 @@ * @param timestamp The timestamp of the status message. * @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) public record Status( @JsonProperty("id") String id, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Sticker.java b/src/main/java/com/whatsapp/api/domain/webhook/Sticker.java index d07528a79..0ffc452e5 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Sticker.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Sticker.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -9,6 +10,7 @@ * @param mimeType The mime type of the media. The caption that describes the media. * @param id The ID of the medi */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Sticker( @JsonProperty("sha256") String sha256, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/System.java b/src/main/java/com/whatsapp/api/domain/webhook/System.java index e198ce338..4b654b9aa 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/System.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/System.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -9,6 +10,7 @@ * @param body Describes the system message event. Supported use cases are: Phone number update: for when a user changes from an old number to a new number. Identity update: for when a user identity has changed. * @param type Supported types are:
  • user_changed_number: for a user changed number notification.
  • user_identity_changed: for user identity changed notification.
*/ +@JsonIgnoreProperties(ignoreUnknown = true) public record System( @JsonProperty("new_wa_id") String newWaId, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Text.java b/src/main/java/com/whatsapp/api/domain/webhook/Text.java index 771521163..4dd1061ca 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Text.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Text.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -7,6 +8,7 @@ * * @param body The text of the text message. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Text( @JsonProperty("body") String body) { 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 8b13033ef..376d94e10 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Value.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Value.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.webhook.type.EventType; @@ -24,6 +25,7 @@ * @param rejectionReason If a request was rejected, this field displays the reason for that rejection. * @param requestedVerifiedName This field displays the name that was sent to be verified. */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Value( @JsonProperty("metadata") Metadata metadata, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Video.java b/src/main/java/com/whatsapp/api/domain/webhook/Video.java index 0168a8c59..a33b07320 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Video.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Video.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -10,6 +11,7 @@ * @param caption Added to Webhooks if it has been previously specified. The caption that describes the media. * @param id The ID of the medi */ +@JsonIgnoreProperties(ignoreUnknown = true) public record Video( @JsonProperty("mime_type") String mimeType, diff --git a/src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java b/src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java index a7904b143..ffb149f16 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.webhook; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; @@ -13,5 +14,6 @@ * * @see Webhooks Setup Guide to more details. **/ +@JsonIgnoreProperties(ignoreUnknown = true) public record WebHookEvent(@JsonProperty("entry") List entry, @JsonProperty("object") String object) { } From 5c2c31089852d3ada5182b9f6a4573aa4bdcd3ee Mon Sep 17 00:00:00 2001 From: Stein Desmet Date: Tue, 2 Jan 2024 14:05:58 +0100 Subject: [PATCH 3/6] Prevent deserialization failure on unknown enums --- .../api/domain/messages/type/MessageType.java | 3 ++- .../java/com/whatsapp/api/domain/webhook/Change.java | 4 ++++ .../com/whatsapp/api/domain/webhook/Message.java | 4 ++++ .../whatsapp/api/domain/webhook/RestrictionInfo.java | 4 ++++ .../java/com/whatsapp/api/domain/webhook/Status.java | 4 ++++ .../java/com/whatsapp/api/domain/webhook/Value.java | 4 ++++ .../whatsapp/api/domain/webhook/type/EventType.java | 10 +++++++++- .../whatsapp/api/domain/webhook/type/FieldType.java | 9 ++++++++- .../api/domain/webhook/type/MessageStatus.java | 12 +++++++++--- .../api/domain/webhook/type/RestrictionType.java | 10 +++++++++- 10 files changed, 57 insertions(+), 7 deletions(-) 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; } From bb88267a7842266aaa2ae96ddce36c486f27b541 Mon Sep 17 00:00:00 2001 From: Stein Desmet Date: Tue, 2 Jan 2024 14:21:36 +0100 Subject: [PATCH 4/6] Replace some strings with enums --- .../com/whatsapp/api/domain/webhook/Interactive.java | 7 ++++++- .../com/whatsapp/api/domain/webhook/WebHookEvent.java | 7 ++++++- .../api/domain/webhook/type/InteractiveType.java | 9 +++++++++ .../whatsapp/api/domain/webhook/type/WebhookType.java | 9 +++++++++ .../whatsapp/api/domain/webhook/WebHookPayloadTest.java | 4 ++-- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/whatsapp/api/domain/webhook/type/InteractiveType.java create mode 100644 src/main/java/com/whatsapp/api/domain/webhook/type/WebhookType.java diff --git a/src/main/java/com/whatsapp/api/domain/webhook/Interactive.java b/src/main/java/com/whatsapp/api/domain/webhook/Interactive.java index d07907d57..0f28ed1f0 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/Interactive.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/Interactive.java @@ -1,7 +1,11 @@ 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.InteractiveType; + +import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE; /** * The type Interactive. @@ -11,11 +15,12 @@ * @param buttonReply Used on Webhooks related to Reply Buttons. Contains a {@link ButtonReply} reply object. */ @JsonIgnoreProperties(ignoreUnknown = true) +@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE) public record Interactive( @JsonProperty("list_reply") ListReply listReply, - @JsonProperty("type") String type, + @JsonProperty("type") InteractiveType type, @JsonProperty("button_reply") ButtonReply buttonReply) { diff --git a/src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java b/src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java index ffb149f16..f520af371 100644 --- a/src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java +++ b/src/main/java/com/whatsapp/api/domain/webhook/WebHookEvent.java @@ -1,10 +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.WebhookType; import java.util.List; +import static com.fasterxml.jackson.annotation.JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE; + /** * This class is a representation of the json object sent by the WhatsApp webhook. * Whenever a trigger event occurs, the WhatsApp Business Platform sees the event and sends a notification to a Webhook URL you have previously specified. @@ -15,5 +19,6 @@ * @see Webhooks Setup Guide to more details. **/ @JsonIgnoreProperties(ignoreUnknown = true) -public record WebHookEvent(@JsonProperty("entry") List entry, @JsonProperty("object") String object) { +@JsonFormat(with = READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE) +public record WebHookEvent(@JsonProperty("entry") List entry, @JsonProperty("object") WebhookType object) { } diff --git a/src/main/java/com/whatsapp/api/domain/webhook/type/InteractiveType.java b/src/main/java/com/whatsapp/api/domain/webhook/type/InteractiveType.java new file mode 100644 index 000000000..1c0bae3d1 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/webhook/type/InteractiveType.java @@ -0,0 +1,9 @@ +package com.whatsapp.api.domain.webhook.type; + +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; + +public enum InteractiveType { + button_reply, list_reply, + @JsonEnumDefaultValue + unknown +} \ No newline at end of file diff --git a/src/main/java/com/whatsapp/api/domain/webhook/type/WebhookType.java b/src/main/java/com/whatsapp/api/domain/webhook/type/WebhookType.java new file mode 100644 index 000000000..2b6a58121 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/webhook/type/WebhookType.java @@ -0,0 +1,9 @@ +package com.whatsapp.api.domain.webhook.type; + +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; + +public enum WebhookType { + whatsapp_business_account, + @JsonEnumDefaultValue + unknown +} \ No newline at end of file diff --git a/src/test/java/com/whatsapp/api/domain/webhook/WebHookPayloadTest.java b/src/test/java/com/whatsapp/api/domain/webhook/WebHookPayloadTest.java index 40f3d6b94..0f6729309 100644 --- a/src/test/java/com/whatsapp/api/domain/webhook/WebHookPayloadTest.java +++ b/src/test/java/com/whatsapp/api/domain/webhook/WebHookPayloadTest.java @@ -210,7 +210,7 @@ void testDeserializationStickerMessage() throws IOException, URISyntaxException var obj = WebHook.constructEvent(payload); - Assertions.assertEquals("whatsapp_business_account", obj.object()); + Assertions.assertEquals("whatsapp_business_account", obj.object().name()); Assertions.assertFalse(obj.entry().isEmpty()); Assertions.assertEquals("880480571844883", obj.entry().get(0).id()); @@ -229,7 +229,7 @@ void testDeserializationVideoMessage() throws IOException, URISyntaxException { var obj = WebHook.constructEvent(payload); - Assertions.assertEquals("whatsapp_business_account", obj.object()); + Assertions.assertEquals("whatsapp_business_account", obj.object().name()); Assertions.assertFalse(obj.entry().isEmpty()); Assertions.assertEquals("880480571844883", obj.entry().get(0).id()); From 66f3be344c65e52c75794219c686bf37754bd168 Mon Sep 17 00:00:00 2001 From: Stein Desmet Date: Tue, 2 Jan 2024 14:35:43 +0100 Subject: [PATCH 5/6] Also ignore unknown fields on message responses --- .../java/com/whatsapp/api/domain/messages/response/Contact.java | 2 ++ .../java/com/whatsapp/api/domain/messages/response/Message.java | 2 ++ .../whatsapp/api/domain/messages/response/MessageResponse.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/main/java/com/whatsapp/api/domain/messages/response/Contact.java b/src/main/java/com/whatsapp/api/domain/messages/response/Contact.java index 877e2b914..4c95f1e35 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/response/Contact.java +++ b/src/main/java/com/whatsapp/api/domain/messages/response/Contact.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.messages.response; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -7,6 +8,7 @@ * The type Contact. */ @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public record Contact( @JsonProperty("input") String input, diff --git a/src/main/java/com/whatsapp/api/domain/messages/response/Message.java b/src/main/java/com/whatsapp/api/domain/messages/response/Message.java index 1208cdde3..24d48bb03 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/response/Message.java +++ b/src/main/java/com/whatsapp/api/domain/messages/response/Message.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.messages.response; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -7,6 +8,7 @@ * The type Message. */ @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public record Message( @JsonProperty("id") String id) { diff --git a/src/main/java/com/whatsapp/api/domain/messages/response/MessageResponse.java b/src/main/java/com/whatsapp/api/domain/messages/response/MessageResponse.java index 78f2c5d72..03f375ce2 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/response/MessageResponse.java +++ b/src/main/java/com/whatsapp/api/domain/messages/response/MessageResponse.java @@ -1,5 +1,6 @@ package com.whatsapp.api.domain.messages.response; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -9,6 +10,7 @@ * The type Message response. */ @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public record MessageResponse( @JsonProperty("messaging_product") String messagingProduct, From f7afc21e9ab02f09f6511edf2305d5152db1f3f5 Mon Sep 17 00:00:00 2001 From: Mauricio Binda da Costa Date: Mon, 6 May 2024 23:55:14 -0300 Subject: [PATCH 6/6] Update pom.xml --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 97f391aaf..c23924e2c 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ 5.11.0 5.10.2 5.0.0-alpha.12 + 2.16.0