@Mapped(attributesAsElements = {"title"})
public void testJSON() throws Exception
{
{
Mapped mapped = TestJAXB.class.getMethod("testJSON").getAnnotation(Mapped.class);
JettisonMappedContext context = new JettisonMappedContext(mapped, Book.class);
StringWriter writer = new StringWriter();
context.createMarshaller().marshal(new Book("Bill Burke", "666", "EJB 3.0"), writer);
System.out.println("Mapped: ");
String val = writer.toString();
System.out.println(val);
// test Mapped attributeAsElement
Assert.assertTrue(val.indexOf("@title") == -1);
}
{
BadgerContext context = new BadgerContext(Book.class);
StringWriter writer = new StringWriter();
context.createMarshaller().marshal(new Book("Bill Burke", "666", "EJB 3.0"), writer);
System.out.println("Badger: ");
System.out.println(writer.toString());
}
Library library = new Library();
ArrayList<Book> books = new ArrayList<Book>();
books.add(new Book("Bill Burke", "555", "JBoss Workbook"));
books.add(new Book("Bill Burke", "666", "EJB 3.0"));
library.setName("BPL");
library.setBooks(books);
{
BadgerContext context = new BadgerContext(Library.class);
StringWriter writer = new StringWriter();
context.createMarshaller().marshal(library, writer);
System.out.println("Badger: ");
String s = writer.toString();
System.out.println(s);
Library lib = (Library) context.createUnmarshaller().unmarshal(new StringReader(s));
Assert.assertEquals(lib.getName(), "BPL");
Assert.assertEquals(lib.getBooks().size(), 2);
}
{
JettisonMappedContext context = new JettisonMappedContext(Library.class);
StringWriter writer = new StringWriter();
context.createMarshaller().marshal(library, writer);
System.out.println("Mapped: ");
String s = writer.toString();
System.out.println(s);
Library lib = (Library) context.createUnmarshaller().unmarshal(new StringReader(s));
Assert.assertEquals(lib.getName(), "BPL");
Assert.assertEquals(lib.getBooks().size(), 2);
}
}