Skip to content

Commit 82b49ec

Browse files
removes unused serializer, adds tests for different types of variables
1 parent 317f350 commit 82b49ec

4 files changed

Lines changed: 6 additions & 41 deletions

File tree

src/main/java/com/mailjet/client/helpers/StringMapSerializer.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main/java/com/mailjet/client/transactional/TransactionalEmail.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.mailjet.client.transactional;
22

3-
import com.google.gson.annotations.JsonAdapter;
43
import com.google.gson.annotations.SerializedName;
5-
import com.mailjet.client.helpers.StringMapSerializer;
64
import lombok.Builder;
75
import lombok.Singular;
86

@@ -179,20 +177,16 @@ public class TransactionalEmail {
179177

180178
/**
181179
* Additional email headers.
182-
* If the passed value type is not String, it will be serialized as a String with JSON representation of the passed object
183180
*/
184181
@Singular
185-
@JsonAdapter(StringMapSerializer.class)
186182
private Map<String, Object> headers;
187183

188184
/**
189185
* Adds variable used to modify the content of your email.
190186
* Specified as {var_name}:{var_value} pairs.
191-
* If the passed value type is not String, it will be serialized as a String with JSON representation of the passed object
192187
* Enter the information in the template text / HTML part by using the [[var:{var_name}]] format.
193188
* Equivalent of using X-MJ-Vars header through SMTP.
194189
*/
195190
@Singular
196-
@JsonAdapter(StringMapSerializer.class)
197191
private Map<String, Object> variables;
198192
}

src/test/java/com/mailjet/client/TransactionalEmailBuilderIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public void SendEmailsRequest_SendsMessage() throws MailjetException, IOExceptio
4545
.attachment(Attachment.fromFile(attachmentPath))
4646
.header("test-header-key", "test-value")
4747
.variable("test-vars-array", new String[] {"a", "b", "c"})
48+
.variable("test-vars-string", "abc")
49+
.variable("test-vars-primitive", 123)
4850
.customID("custom-id-value")
4951
.build();
5052

src/test/java/com/mailjet/client/TransactionalEmailBuilderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public static void initialize() throws IOException {
4646
public void transactionalEmail_WithVariables_ShouldCorrectlyPassVariables() throws MailjetException, InterruptedException {
4747

4848
// arrange
49-
String expectedBody = "{\"Messages\":[{\"Cc\":[],\"TrackClicks\":\"enabled\",\"Bcc\":[],\"Priority\":3,\"Headers\":{},\"From\":{\"Email\":\"xxxxxxxx@xxxxxxx.com\",\"Name\":\"xxxxxxxx xxxxxxxxxx\"},\"Attachments\":[],\"TemplateLanguage\":true,\"TrackOpens\":\"enabled\",\"Variables\":{\"E_DATE\":\"a string text\",\"E_YEAR\":\"another text\",\"E_MAIL_ID\":\"a last text example\"},\"CustomID\":\"8c0725fa-403c-496e-ac7e-xxxxxxxxx\",\"InlinedAttachments\":[],\"To\":[{\"Email\":\"xxxxxxxx@xxxxxxx.com\",\"Name\":\"xxxxxxxx xxxxxxxxxx\"}],\"TemplateID\":1234567}]}";
49+
String expectedBody = "{\"Messages\":[{\"Cc\":[],\"TrackClicks\":\"enabled\",\"Bcc\":[],\"Priority\":3,\"Headers\":{},\"From\":{\"Email\":\"xxxxxxxx@xxxxxxx.com\",\"Name\":\"xxxxxxxx xxxxxxxxxx\"},\"Attachments\":[],\"TemplateLanguage\":true,\"TrackOpens\":\"enabled\",\"Variables\":{\"E_DATE\":\"a string text\",\"E_ARRAY\":[\"val1\",\"val2\"],\"E_MAIL_ID\":123},\"CustomID\":\"8c0725fa-403c-496e-ac7e-xxxxxxxxx\",\"InlinedAttachments\":[],\"To\":[{\"Email\":\"xxxxxxxx@xxxxxxx.com\",\"Name\":\"xxxxxxxx xxxxxxxxxx\"}],\"TemplateID\":1234567}]}";
5050

5151
mockWebServer.enqueue(new MockResponse().setResponseCode(201).setBody("{}"));
5252

53-
Map<String, String> variables = new HashMap<>();
53+
Map<String, Object> variables = new HashMap<>();
5454
variables.put("E_DATE", "a string text");
55-
variables.put("E_YEAR", "another text");
56-
variables.put("E_MAIL_ID", "a last text example");
55+
variables.put("E_ARRAY", new String[]{"val1", "val2"});
56+
variables.put("E_MAIL_ID", 123);
5757

5858
TransactionalEmail message = TransactionalEmail
5959
.builder()

0 commit comments

Comments
 (0)