From f04b1c21e42525377d01b5d102006ae4efe5d4b1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 12 Jul 2016 17:51:27 +0300 Subject: jackson-databind serialization with tests --- src/test/java/com/juick/tests/JsonTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/test/java/com/juick/tests') 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 -- cgit v1.2.3