@Test public void testSerialize() { SFSSerializer sfsSerializer = new SFSSerializer(); SubEntity subEntity = new SubEntity(); subEntity.setLongField(10L); subEntity.setStringsList(Arrays.asList("testString")); Entity entity = new Entity(); entity.setIntField(100); entity.setStringField("string"); entity.setSubEntity(subEntity); entity.setSubEntities(Arrays.asList(new SubEntity(100L), new SubEntity(100L))); entity.setNotDeserializable("value1"); entity.fieldWithoutGetter = "value"; entity.setNotSerializable("value2"); entity.setEnumField(Entity.Color.black); entity.setColors(Arrays.asList(Entity.Color.black, Entity.Color.white)); entity.fieldCustomSerializable = 20L; entity.totallyIgnoredField = "value"; ISFSObject sObj = sfsSerializer.serialize(entity); assertEquals(entity.getIntField(), sObj.getInt("intField")); assertEquals(entity.fieldWithoutGetter, sObj.getUtfString("fieldWithoutGetter")); assertEquals(entity.getEnumField().name(), sObj.getUtfString("enumField")); assertEquals(entity.getNameToBeChanged(), sObj.getUtfString("changedName")); assertEquals(entity.getNotDeserializable(), sObj.getUtfString("notDeserializable")); assertEquals(20, sObj.getInt("fieldCustomSerializable").intValue()); Collection<String> colors = sObj.getUtfStringArray("colors"); assertTrue(colors.contains(entity.getColors().get(1).name())); assertNull(sObj.getUtfString("totallyIgnoredField")); assertNull(sObj.getUtfString("notSerializable")); assertNull(sObj.getUtfString("ignoredField")); assertEquals(entity.getStringField(), sObj.getUtfString("stringField")); assertNotNull(sObj.getSFSObject("subEntity")); assertEquals(subEntity.getLongField(), sObj.getSFSObject("subEntity").getLong("longField")); assertNotNull(sObj.getSFSArray("subEntities")); Iterator<SFSDataWrapper> iterator = sObj.getSFSArray("subEntities").iterator(); assertEquals(100L, ((SFSObject) iterator.next().getObject()).getLong("longField").longValue()); assertEquals( "testString", sObj.getSFSObject("subEntity").getUtfStringArray("stringsList").iterator().next()); }
@CustomListItemDeserializer(listName = "wildcardList") public TransportObject deserializeWildcardItem(ISFSObject object) { SubEntity res = new SubEntity(); res.setLongField(object.getLong("longField")); return res; }