@Test public void testDeserializeCustom() { SFSSerializer sfsSerializer = new SFSSerializer(); ISFSObject entityObj = new SFSObject(); entityObj.putInt("intField", 10); ISFSArray subArray = new SFSArray(); ISFSArray subCustomArray = new SFSArray(); SFSObject subObj1 = new SFSObject(); SFSObject subCustomObj = new SFSObject(); subObj1.putLong("longField", 30L); subCustomObj.putLong("longField", 99L); subArray.addSFSObject(subObj1); subCustomArray.addSFSObject(subCustomObj); entityObj.putSFSArray("wildcardList", subArray); entityObj.putSFSArray("wildcardedListCustom", subCustomArray); Entity entity = new Entity(); sfsSerializer.deserialize(entity, entityObj); assertNotNull("Wildcarded deserialized list must not be null!", entity.getWildcardList()); assertFalse( "Wildcarded deserialized list must not be empty!", entity.getWildcardList().isEmpty()); assertEquals(30L, ((SubEntity) entity.getWildcardList().get(0)).getLongField().longValue()); assertEquals( 99L, ((SubEntity) entity.getWildcardedListCustom().get(0)).getLongField().longValue()); }
@Test public void testDeserialize() { SFSSerializer sfsSerializer = new SFSSerializer(); ISFSObject subEntityObj = new SFSObject(); subEntityObj.putLong("longField", 20L); ISFSObject entityObj = new SFSObject(); entityObj.putInt("intField", 10); entityObj.putSFSObject("subEntity", subEntityObj); entityObj.putUtfString("notDeserializable", "value1"); entityObj.putUtfString("notSerializable", "value2"); entityObj.putUtfString("enumField", "white"); entityObj.putUtfString("changedName", "changedValue"); entityObj.putUtfString("fieldWithoutGetter", "value"); entityObj.putInt("fieldCustomSerializable", 10); entityObj.putUtfString("totallyIgnoredField", "value"); entityObj.putUtfStringArray("colors", Arrays.asList("black", "black", "white")); ISFSArray subArray = new SFSArray(); SFSObject subObj1 = new SFSObject(); subObj1.putLong("longField", 30L); subObj1.putUtfStringArray("stringsList", Arrays.asList("testString")); SFSObject subObj2 = new SFSObject(); subArray.addSFSObject(subObj1); subArray.addSFSObject(subObj2); entityObj.putSFSArray("subEntities", subArray); Entity entity = sfsSerializer.deserialize(Entity.class, entityObj); assertEquals(Entity.Color.white, entity.getEnumField()); assertEquals(Entity.Color.white, entity.getColors().get(2)); assertEquals(entityObj.getInt("intField"), entity.getIntField()); assertEquals((Long) 10L, entity.fieldCustomSerializable); assertEquals(entityObj.getUtfString("fieldWithoutGetter"), entity.fieldWithoutGetter); assertEquals(entityObj.getUtfString("notSerializable"), entity.getNotSerializable()); assertEquals(entityObj.getUtfString("changedName"), entity.getNameToBeChanged()); assertNull(entity.getNotDeserializable()); assertNull(entity.totallyIgnoredField); assertEquals(subEntityObj.getLong("longField"), entity.getSubEntity().getLongField()); assertNotNull(entity.getSubEntities()); assertFalse(entity.getSubEntities().isEmpty()); assertEquals(30L, entity.getSubEntities().get(0).getLongField().longValue()); assertEquals("testString", entity.getSubEntities().get(0).getStringsList().get(0)); }