Ejemplo n.º 1
0
  @Test
  public void testPerson() {
    TestPerson hh = new TestPerson();
    hh.setUserName("hanhan");
    hh.setAge(30);

    TestPerson parent = new TestPerson();
    parent.setUserName("hanrenjun");
    parent.setAge(60);

    hh.setParent(parent);

    String xmlStr = XmlUtils.toXML(hh, "person", TestPerson.class).trim();

    System.out.println("testPerson xml:\n " + xmlStr);

    TestPerson newHH = XmlUtils.toBean(xmlStr, "person", TestPerson.class);
    Assert.assertEquals(hh.getUserName(), newHH.getUserName());
  }
Ejemplo n.º 2
0
  @Test
  public void testPersonList() {
    TestPerson hh = new TestPerson();
    hh.setUserName("hanhan");
    hh.setAge(30);

    TestPerson parent = new TestPerson();
    parent.setUserName("hanrenjun");
    parent.setAge(60);

    hh.setParent(parent);

    Collection<TestPerson> lists = CUtils.newHashSet();
    lists.add(hh);

    String xmlStr = XmlUtils.toXML(lists, "personlist", Set.class, "person", TestPerson.class);

    System.out.println("testPersonList xml:\n " + xmlStr);

    Collection<TestPerson> list =
        XmlUtils.toBean(xmlStr, "personlist", List.class, "person", TestPerson.class);
    Assert.assertEquals(hh.getUserName(), list.iterator().next().getUserName());
  }