Issue Summary
It's not possible to disable tracking settings for a single email, e.g. click_tracking, because the "enabled" flag does not get serialised to JSON if it is false (default value) and the SendGrid server rejects the request as a result of that. In this example I used click_tracking, but this should also be changed for other tracking settings.
Steps to Reproduce
- This is how I disable click tracking for a single email
TrackingSettings trackingSettings = new TrackingSettings();
// disable click tracking
ClickTrackingSetting clickTrackingSetting = new ClickTrackingSetting();
clickTrackingSetting.setEnable(false);
clickTrackingSetting.setEnableText(false);
trackingSettings.setClickTrackingSetting(clickTrackingSetting);
this.mail.setTrackingSettings(trackingSettings); // com.sendgrid.Mail
- This is how I send the email
Request request = new Request();
this.mail.addPersonalization(personalization);
request.method = Method.POST;
request.endpoint = "mail/send";
request.body = mail.build(); // this is the important part
Response response = this.api(request);
-
mail.build() does not include the click_tracking settings. Those "enable" booleans will not get serialized if they are false because of @JsonInclude(Include.NON_DEFAULT) in ClickTrackingSetting (false is the default value of boolean). mail.build() creates a JSON that looks like this: "tracking_settings":{"click_tracking":{}} when I want to disable click tracking.
I expect it to look like this: "tracking_settings":{"click_tracking":{"enable": false, "enable_text": false}}
-
The SendGrid server rejects the JSON created by mail.build() containing "tracking_settings":{"click_tracking":{}} but accepts my manually created JSON containing"tracking_settings":{"click_tracking":{"enable": false, "enable_text": false}}
Possible solution:
Instead of boolean(primitive) with default value false, use Boolean(object) with default value null to enable/disable settings.
Example ClickTrackingSetting.java:
@JsonProperty("enable") private Boolean enable;
instead of
@JsonProperty("enable") private boolean enable;
Technical details:
- sendgrid-java Version: v3.1.0
Issue Summary
It's not possible to disable tracking settings for a single email, e.g. click_tracking, because the "enabled" flag does not get serialised to JSON if it is false (default value) and the SendGrid server rejects the request as a result of that. In this example I used click_tracking, but this should also be changed for other tracking settings.
Steps to Reproduce
mail.build()does not include the click_tracking settings. Those "enable" booleans will not get serialized if they are false because of@JsonInclude(Include.NON_DEFAULT)inClickTrackingSetting(false is the default value of boolean).mail.build()creates a JSON that looks like this:"tracking_settings":{"click_tracking":{}}when I want to disable click tracking.I expect it to look like this:
"tracking_settings":{"click_tracking":{"enable": false, "enable_text": false}}The SendGrid server rejects the JSON created by
mail.build()containing"tracking_settings":{"click_tracking":{}}but accepts my manually created JSON containing"tracking_settings":{"click_tracking":{"enable": false, "enable_text": false}}Possible solution:
Instead of
boolean(primitive) with default valuefalse, useBoolean(object) with default valuenullto enable/disable settings.Example ClickTrackingSetting.java:
@JsonProperty("enable") private Boolean enable;instead of
@JsonProperty("enable") private boolean enable;Technical details: