Пример #1
0
  @Test
  public void testAllTypeObj() throws Exception {
    // 序列化
    AllTypeObject testObj = getTestObj();
    String xml = XBlink.toXml(testObj);

    // 反序列化
    AllTypeObject testObj2 = (AllTypeObject) XBlink.fromXml(xml);

    // 验证
    Assert.assertTrue(testObj2.getAbc().endsWith("abc"));
    Assert.assertTrue(testObj2.getaDate() != null);
    Assert.assertTrue(testObj2.getI() == 34);
    Assert.assertTrue(testObj2.getEnumForSeason().equals(EnumForSeason.SPRING));
    long[] testArray = testObj2.getNum();
    Assert.assertTrue(testArray[0] == 3);
    Assert.assertTrue(testArray[1] == 555);
    Assert.assertTrue(testArray[2] == 676767);
    List<String> strs = testObj2.getStrs();
    Assert.assertTrue(strs.contains("a123"));
    Assert.assertTrue(strs.contains("b456"));
    Assert.assertTrue(strs.contains("c789"));
    Map<Integer, Object> objMap = testObj2.getObjMap();
    Assert.assertTrue(objMap.get(1).equals("teststr"));
    Assert.assertTrue(objMap.get(2) != null);
    Assert.assertTrue(objMap.get(3) != null);
    Assert.assertTrue(objMap.get(4) != null);
    Person joe = (Person) objMap.get(2);
    Assert.assertTrue(objMap.get(3) == joe.getFax());
    Assert.assertTrue(objMap.get(4) == joe.getPhone());
    Set<Object> objSet = testObj2.getObjSet();
    Assert.assertTrue(objSet.contains("nnn"));
    Assert.assertTrue(objSet.contains(joe));
  }
Пример #2
0
  public AllTypeObject getTestObj() {

    List<String> strs = getList();

    Set<Object> objSet = getSet();

    Map<Integer, Object> objMap = getMap();

    AllTypeObject allTypeObject = new AllTypeObject();
    allTypeObject.setAbc("abc");
    allTypeObject.setaDate(new Date());
    allTypeObject.setI(34);
    allTypeObject.setEnumForSeason(EnumForSeason.SPRING);
    allTypeObject.setNum(new long[] {3, 555, 676767});
    allTypeObject.setStrs(strs);
    allTypeObject.setObjSet(objSet);
    allTypeObject.setObjMap(objMap);

    return allTypeObject;
  }