diff options
author | 2016-07-12 17:39:33 +0300 | |
---|---|---|
committer | 2016-07-12 17:39:33 +0300 | |
commit | bdbf65e0a50758bfcc88e1cc9c501eeed4e7e45d (patch) | |
tree | 756e8b29b2442c82ae50a3548c772f4a65b6d1ef /src/test/java/com/juick/tests/JsonTests.java | |
parent | 291da35b1bf7dcd66bf621160f907872fd0f7825 (diff) |
jackson-databind WIP
Diffstat (limited to 'src/test/java/com/juick/tests/JsonTests.java')
-rw-r--r-- | src/test/java/com/juick/tests/JsonTests.java | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/test/java/com/juick/tests/JsonTests.java b/src/test/java/com/juick/tests/JsonTests.java index babcc6c7..ab0d6283 100644 --- a/src/test/java/com/juick/tests/JsonTests.java +++ b/src/test/java/com/juick/tests/JsonTests.java @@ -1,9 +1,15 @@ package com.juick.tests; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.Message; +import com.juick.User; import com.juick.json.MessageSerializer; +import com.juick.json.UserSerializer; +import org.json.JSONObject; import org.junit.Test; +import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.TimeZone; @@ -24,6 +30,23 @@ public class JsonTests { } catch (ParseException e) { e.printStackTrace(); } - + } + @Test + public void serializersTest() throws IOException { + User user = new User(); + user.setUName("ugnich"); + user.setUID(1); + user.setFullName("Anton Ugnich"); + UserSerializer userSerializer = new UserSerializer(); + JSONObject handmadeJson = userSerializer.serialize(user); + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); + User jacksonUser = mapper.readValue(handmadeJson.toString(), User.class); + assertEquals("jackson should deserialize ugnich json", user, jacksonUser); + String jacksonString = mapper.writeValueAsString(user); + JSONObject jacksonJson = new JSONObject(jacksonString); + assertEquals("jackson should serialize as ugnich", handmadeJson.length(), jacksonJson.length()); } }
\ No newline at end of file |