コード例 #1
0
  @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));
  }
コード例 #2
0
 @CustomListItemDeserializer(listName = "wildcardList")
 public TransportObject deserializeWildcardItem(ISFSObject object) {
   SubEntity res = new SubEntity();
   res.setLongField(object.getLong("longField"));
   return res;
 }