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

Lenient deserialization. #154

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<org.mockito.version>5.11.0</org.mockito.version>
<org.junit.jupiter.version>5.10.2</org.junit.jupiter.version>
<com.squareup.okhttp3.version>5.0.0-alpha.12</com.squareup.okhttp3.version>

<jackson.version>2.16.0</jackson.version>
</properties>

<distributionManagement>
Expand All @@ -62,6 +62,23 @@
<artifactId>okhttp</artifactId>
<version>${com.squareup.okhttp3.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>

<!--tests-->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;

/**
* The type Contact.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record Contact(

@JsonProperty("input") String input,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;

/**
* The type Message.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record Message(

@JsonProperty("id") String id,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -9,6 +10,7 @@
* The type Message response.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record MessageResponse(

@JsonProperty("messaging_product") String messagingProduct,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -78,7 +79,7 @@ public enum MessageType {
/**
* Unknown message type.
*/
UNKNOWN("unknown"), //
@JsonEnumDefaultValue UNKNOWN( "unknown"), //
/**
* Video message type.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Address.java
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Audio.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/BanInfo.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Button.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Change.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
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.
*
* @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)
@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”.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Contact.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Context.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
}
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Document.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Email.java
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Entry.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(

/*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Error.java
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/ErrorData.java
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Image.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +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.
Expand All @@ -9,11 +14,13 @@
* @param type Contains the type of interactive object. Supported options are:<ul> <li>button_reply: for responses of Reply Buttons.</li> <li>list_reply: for responses to List Messages and other interactive objects.</li></ul>
* @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) {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/ListReply.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatsapp.api.domain.webhook;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/whatsapp/api/domain/webhook/Location.java
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading