@Test public void testParameterisedDeserialisationOfComplexObject() throws SerialisationException { SimpleTestObject test = new SimpleTestObject(); test.setX("Test"); byte[] b = JSONSerialiser.serialise(test); SimpleTestObject o = JSONSerialiser.deserialise(b, SimpleTestObject.class); assertEquals(SimpleTestObject.class, o.getClass()); assertEquals("Test", o.getX()); }
@Test public void shouldPrettyPrintWhenSerialisingAndSetToPrettyPrint() throws SerialisationException { SimpleTestObject test = new SimpleTestObject(); test.setX("TestValue1"); byte[] bytes = JSONSerialiser.serialise(test, true); JsonAssert.assertEquals(String.format("{%n \"x\" : \"TestValue1\"%n}"), new String(bytes)); }
@Test public void shouldSerialiseObjectWithFieldX() throws Exception { // Given final SimpleTestObject obj = new SimpleTestObject(); // When final String json = new String(JSONSerialiser.serialise(obj), CommonConstants.UTF_8); // Then assertTrue(json.contains("x")); }
@Test public void shouldNotPrettyPrintByDefaultWhenSerialising() throws SerialisationException { SimpleTestObject test = new SimpleTestObject(); test.setX("TestValue1"); byte[] bytes = JSONSerialiser.serialise(test); assertEquals("{\"x\":\"TestValue1\"}", new String(bytes)); }
@Test public void shouldSerialiseObjectWithoutFieldX() throws Exception { // Given final SimpleTestObject obj = new SimpleTestObject(); // When final String json = new String(JSONSerialiser.serialise(obj, "x"), CommonConstants.UTF_8); // Then assertFalse(json.contains("x")); }
@Test public void testDAOSerialisation() throws SerialisationException { SimpleTestObject test = new SimpleTestObject(); test.setX("Test"); byte[] b = JSONSerialiser.serialise(test); Object o = JSONSerialiser.deserialise(b, SimpleTestObject.class); assertEquals(SimpleTestObject.class, o.getClass()); assertEquals("Test", ((SimpleTestObject) o).getX()); }
@Test(expected = SerialisationException.class) public void testParameterisedDeserialisationOfComplexObjectToIncorrectType() throws SerialisationException { SimpleTestObject test = new SimpleTestObject(); test.setX("Test"); byte[] b = JSONSerialiser.serialise(test); JSONSerialiser.deserialise(b, Integer.class); }
var instance = new SimpleTestObject(); console.log(readGetters(Object.getPrototypeOf(instance)));
@Test public void testDAOSerialisation() throws SerialisationException { final SimpleTestObject test = new SimpleTestObject(); test.setX("Test"); final byte[] b = serialiser.serialise(test); final Object o = serialiser.deserialise(b); assertEquals(SimpleTestObject.class, o.getClass()); assertEquals("Test", ((SimpleTestObject) o).getX()); }
@SuppressWarnings("unchecked") public JSONSerialiserTest() { ParameterisedTestObject<Object> paramTest = new ParameterisedTestObject<>(); paramTest.setX("Test"); paramTest.setK(2); SimpleTestObject simpleTestObject = new SimpleTestObject(); simpleTestObject.setX("Test"); this.historicSerialisationPairs = new Pair[]{ new Pair(simpleTestObject, new byte[]{123, 34, 120, 34, 58, 34, 84, 101, 115, 116, 34, 125}), new Pair(paramTest, new byte[]{123, 34, 120, 34, 58, 34, 84, 101, 115, 116, 34, 44, 34, 107, 34, 58, 50, 125}) }; }