Skip to content

Commit

Permalink
CAMEL-21363: Adding @JsonIgnoreProperties(ignoreUnknown = true) to pr…
Browse files Browse the repository at this point in the history
…event the component from crashing if WhatsApp introduces a new field in the message. Adding the "message_status" field to Message. (#16009)

Co-authored-by: Claus Ibsen <[email protected]>
  • Loading branch information
juniiorviani and davsclaus authored Oct 19, 2024
1 parent 094fe6c commit f239050
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
*/
package org.apache.camel.component.whatsapp.model;

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

@JsonIgnoreProperties(ignoreUnknown = true)
public class Contact {

private String input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@
*/
package org.apache.camel.component.whatsapp.model;

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

@JsonIgnoreProperties(ignoreUnknown = true)
public class Message {

private String id;

@JsonProperty("message_status")
private String messageStatus;

public Message() {
}

Expand All @@ -30,4 +37,12 @@ public String getId() {
public void setId(String id) {
this.id = id;
}

public String getMessageStatus() {
return messageStatus;
}

public void setMessageStatus(String messageStatus) {
this.messageStatus = messageStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import java.util.List;

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

@JsonIgnoreProperties(ignoreUnknown = true)
public class MessageResponse {

@JsonProperty("messaging_product")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ private void assertResponse(MessageResponse response) {
Assertions.assertThat(response.getMessages().get(0).getId()).isNotNull();
}

private void assertTemplateResponse(MessageResponse response) {
Assertions.assertThat(response).isNotNull();
Assertions.assertThat(response.getMessages()).isNotNull();
Assertions.assertThat(response.getMessages().get(0).getId()).isNotNull();
Assertions.assertThat(response.getMessages().get(0).getMessageStatus()).isNotNull();
}

@Test
public void testMediaStickerMessage() {
MediaMessage mediaMessage = new MediaMessage();
Expand Down Expand Up @@ -216,7 +223,7 @@ public void testTemplateMessage() throws IOException {

MessageResponse response = (MessageResponse) template.requestBody("whatsapp://" + phoneNumberId, request);

assertResponse(response);
assertTemplateResponse(response);
}

@Test
Expand Down

0 comments on commit f239050

Please sign in to comment.