diff options
author | Vitaly Takmazov | 2016-07-12 17:51:27 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-07-12 17:51:27 +0300 |
commit | f04b1c21e42525377d01b5d102006ae4efe5d4b1 (patch) | |
tree | 1d9f9d00765049adff2319bdb8f2f3fa7ac2a0ba /src/test/java/com/juick/tests/JsonTests.java | |
parent | bdbf65e0a50758bfcc88e1cc9c501eeed4e7e45d (diff) |
jackson-databind serialization with tests
Diffstat (limited to 'src/test/java/com/juick/tests/JsonTests.java')
-rw-r--r-- | src/test/java/com/juick/tests/JsonTests.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/java/com/juick/tests/JsonTests.java b/src/test/java/com/juick/tests/JsonTests.java index ab0d6283..8378d7f1 100644 --- a/src/test/java/com/juick/tests/JsonTests.java +++ b/src/test/java/com/juick/tests/JsonTests.java @@ -3,6 +3,7 @@ package com.juick.tests; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.Message; +import com.juick.Tag; import com.juick.User; import com.juick.json.MessageSerializer; import com.juick.json.UserSerializer; @@ -12,6 +13,7 @@ import org.junit.Test; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Date; import java.util.TimeZone; import static org.junit.Assert.assertEquals; @@ -48,5 +50,19 @@ public class JsonTests { String jacksonString = mapper.writeValueAsString(user); JSONObject jacksonJson = new JSONObject(jacksonString); assertEquals("jackson should serialize as ugnich", handmadeJson.length(), jacksonJson.length()); + Message msg = new Message(); + msg.setMID(1); + msg.setUser(user); + msg.setText("yo"); + msg.setDate(new Date()); + msg.Tags.add(new Tag("test")); + msg.Tags.add(new Tag("json")); + MessageSerializer messageSerializer = new MessageSerializer(); + JSONObject handmadeJsonMessage = messageSerializer.serialize(msg); + Message jacksonMessage = mapper.readValue(handmadeJsonMessage.toString(), Message.class); + assertEquals("jackson should deserialize ugnich json", msg, jacksonMessage); + String jacksonStringMessage = mapper.writeValueAsString(jacksonMessage); + JSONObject jacksonJsonMessage = new JSONObject(jacksonStringMessage); + assertEquals("jackson should serialize as ugnich", handmadeJsonMessage.length(), jacksonJsonMessage.length()); } }
\ No newline at end of file |