@Test public void testJsonComplexObjectEmpty() { String src = "{\"primitives\":null,\"listOfPrimitives\":[], \"arrayOfPrimitives\": null}"; ComplexObject co = genson.deserialize(src, ComplexObject.class); assertNull(co.getPrimitives()); assertTrue(co.getListOfPrimitives().size() == 0); assertNull(co.getArrayOfPrimitives()); }
@Test public void testJsonComplexObject() { ComplexObject coo = new ComplexObject( createPrimitives(), Arrays.asList(createPrimitives(), createPrimitives()), new Primitives[] {createPrimitives(), createPrimitives()}); ComplexObject co = genson.deserialize(coo.jsonString(), ComplexObject.class); ComplexObject.assertCompareComplexObjects(co, coo); }
public String jsonString() { StringBuilder sb = new StringBuilder(); sb.append("{\"list\":["); if (list != null) { for (int i = 0; i < list.size(); i++) sb.append(list.get(i).jsonString()).append(','); sb.append(list.get(list.size() - 1).jsonString()); } sb.append("],\"o1\":") .append(o1.jsonString()) .append(",\"o2\":") .append(o2.jsonString()) .append(",\"ooooooSkipMe\":") .append(o2.jsonString()) .append(",\"p\":") .append(p.jsonString()) .append('}'); return sb.toString(); }
@Test public void testJsonComplexObjectSkipValue() { ComplexObject coo = new ComplexObject( createPrimitives(), Arrays.asList( createPrimitives(), createPrimitives(), createPrimitives(), createPrimitives(), createPrimitives(), createPrimitives()), new Primitives[] {createPrimitives(), createPrimitives()}); DummyWithFieldToSkip dummy = new DummyWithFieldToSkip(coo, coo, createPrimitives(), Arrays.asList(coo)); DummyWithFieldToSkip dummy2 = genson.deserialize(dummy.jsonString(), DummyWithFieldToSkip.class); ComplexObject.assertCompareComplexObjects(dummy.getO1(), dummy2.getO1()); ComplexObject.assertCompareComplexObjects(dummy.getO2(), dummy2.getO2()); Primitives.assertComparePrimitives(dummy.getP(), dummy2.getP()); }