示例#1
0
  @Test
  @Ignore
  public void testSerialization() throws Exception {
    Root unmarshalledRoot = new Root();
    EmailAddress unmarshalledObject = createFixture();
    unmarshalledRoot.setEmailAddress(unmarshalledObject);

    // Marshall
    JAXBContext context = JAXBContext.newInstance(Root.class, EmailAddress.class);
    Marshaller marshaller = context.createMarshaller();
    StringWriter writer = new StringWriter();
    marshaller.marshal(unmarshalledRoot, writer);
    String outString = writer.toString();
    assertTrue(outString.contains("<emailAddress"));

    // Unmarshall
    context = JAXBContext.newInstance(Root.class, EmailAddress.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    StringReader reader = new StringReader(outString);
    Root marshalledRoot = (Root) unmarshaller.unmarshal(reader);
    Assert.isTrue(unmarshalledRoot.equals(marshalledRoot));
    assertEquals(unmarshalledRoot, marshalledRoot);
  }