Skip to content

Commit b056a96

Browse files
authored
Merge pull request #90 from systoyanov/83-handle-float-properties-contact-data
Handle float number format properties in contact data
2 parents aedb6e7 + 1e92e60 commit b056a96

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/main/java/com/mailjet/client/MailjetRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.mailjet.client;
1818

19+
import static com.mailjet.client.MailjetRequestUtil.decodeDecimals;
20+
1921
import java.io.IOException;
2022
import java.io.UnsupportedEncodingException;
2123
import java.net.MalformedURLException;
@@ -190,7 +192,7 @@ public MailjetRequest setBody(HashMap<String, Object> json) {
190192
* @return the stringified body
191193
*/
192194
public String getBody() {
193-
return _data == null ? _body.toString() : Base64.encode(_data.getBytes());
195+
return _data == null ? decodeDecimals(_body.toString()) : Base64.encode(_data.getBytes());
194196
}
195197

196198
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.mailjet.client;
2+
3+
import java.math.BigDecimal;
4+
5+
/**
6+
*
7+
* @author s.stoyanov
8+
*
9+
*/
10+
public final class MailjetRequestUtil {
11+
12+
private MailjetRequestUtil() {
13+
}
14+
15+
public static String encodeDecimal(BigDecimal value) {
16+
return value != null ? "\f" + (value.scale() != 0 ? value : value.setScale(1)).toString() + "\f" : null;
17+
}
18+
19+
public static String decodeDecimals(String payload) {
20+
return payload != null ? payload.replaceAll("\"\\\\f([^\"]+)\\\\f\"", "$1") : null;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)