Issue Summary
Serializing a Mail object to/from JSON does not result in equivalent objects.
Steps to Reproduce
Email to = new Email("[email protected]");
Content content = new Content(MIMETYPE_HTML, "test");
Email from = new Email("[email protected]");
Mail mail = new Mail(from, "subject", to, content);
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(mail);
Mail deserialized = mapper.readValue(json, Mail.class);
System.out.println(ReflectionToStringBuilder.toString(deserialized));
assertThat(deserialized, sameBeanAs(mail));
sameBeanAs is in the shazamcrest library and performs a recursive deep equality check.
The first issue is that the from attribute is not deserialized correctly:
com.sendgrid.Mail@401e7803[from=<null>,subject=subject,personalization=[com.sendgrid.Personalization@43a0cee9],content=[com.sendgrid.Content@eb21112],attachments=<null>,templateId=<null>,sections=<null>,headers=<null>,categories=<null>,customArgs=<null>,sendAt=0,batchId=<null>,asm=<null>,ipPoolId=<null>,mailSettings=<null>,trackingSettings=<null>,replyTo=<null>]
This seems to be because the Mail object has public attributes and non-standard getters:
public class Mail {
@JsonProperty("from")
public Email from;
//...
@JsonProperty("from")
public Email getFrom(Email from) {
return from;
}
public void setFrom(Email from) {
this.from = from;
}
// ...
}
The goal is to write a Mail object to a queue so that we can have a process that manages a circuit breaker, rate limiting, retries and DLQ behavior. Right now, I can write the JSON to the queue, but it doesn't deserialize properly when being read.
Technical details:
- sendgrid-java Version: 3.2.0 from Maven Central
- Java Version: 1.8
- Jackson Version: 2.8.7
Issue Summary
Serializing a
Mailobject to/from JSON does not result in equivalent objects.Steps to Reproduce
sameBeanAsis in the shazamcrest library and performs a recursive deep equality check.The first issue is that the
fromattribute is not deserialized correctly:com.sendgrid.Mail@401e7803[from=<null>,subject=subject,personalization=[com.sendgrid.Personalization@43a0cee9],content=[com.sendgrid.Content@eb21112],attachments=<null>,templateId=<null>,sections=<null>,headers=<null>,categories=<null>,customArgs=<null>,sendAt=0,batchId=<null>,asm=<null>,ipPoolId=<null>,mailSettings=<null>,trackingSettings=<null>,replyTo=<null>]This seems to be because the
Mailobject has public attributes and non-standard getters:The goal is to write a
Mailobject to a queue so that we can have a process that manages a circuit breaker, rate limiting, retries and DLQ behavior. Right now, I can write the JSON to the queue, but it doesn't deserialize properly when being read.Technical details: