aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/tests/JsonTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/juick/tests/JsonTests.java')
-rw-r--r--src/test/java/com/juick/tests/JsonTests.java25
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