Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 31db293

Browse files
author
Rustam Aliyev
committed
Remove empty (null) message metadata entries. #49
1 parent 2bac644 commit 31db293

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

itests/src/test/java/com/elasticinbox/itests/RestV2IT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ public void messageAddListViewDeletePurgeTest() throws IOException
341341
body(messageId + ".from.address", hasItems(containsString("@"))).
342342
body(messageId + ".to.address", hasItems(containsString("@"))).
343343
body(messageId + ".subject", is(notNullValue())).
344+
body(messageId, not(hasKey("bcc"))).
344345
when().
345346
get(REST_PATH + "/mailbox/label/{labelId}?metadata=true&count=2&start={messageId}");
346347

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.elasticinbox.common.utils;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
import org.junit.Test;
9+
10+
public class JSONUtilsTest
11+
{
12+
@Test
13+
public void testNullValueSerialization()
14+
{
15+
Map<String, String> testMap = new HashMap<String, String>();
16+
testMap.put("key1", "val1");
17+
testMap.put("key2", null);
18+
19+
byte[] bytes = JSONUtils.fromObject(testMap);
20+
String result = new String(bytes);
21+
22+
assertFalse(result.contains("null"));
23+
}
24+
25+
}

modules/core/src/main/java/com/elasticinbox/core/model/Message.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.util.Set;
3838

3939
import com.fasterxml.jackson.annotation.JsonIgnore;
40+
import com.fasterxml.jackson.annotation.JsonInclude;
41+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
4042

4143
import com.elasticinbox.core.blob.BlobURI;
4244

@@ -52,6 +54,7 @@
5254
* @see {@link MimePart}
5355
* @see <a href="http://tools.ietf.org/html/rfc3501#section-6.4.5">RFC3501</a>
5456
*/
57+
@JsonInclude(Include.NON_NULL)
5558
public class Message
5659
{
5760
private AddressList from;

0 commit comments

Comments
 (0)