Package org.jboss.resteasy.plugins.providers.jaxb.json

Examples of org.jboss.resteasy.plugins.providers.jaxb.json.JettisonMappedContext


   @Path("books/mapped.html")
   @Produces("text/html")
   public String getBooksMappedText() throws Exception
   {
      BookListing listing = getListing();
      JettisonMappedContext context = new JettisonMappedContext(BookListing.class);
      StringWriter writer = new StringWriter();
      Marshaller marshaller = context.createMarshaller();
      marshaller.marshal(listing, writer);
      return writer.toString();
   }
View Full Code Here


   @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);
      }
   }
View Full Code Here

   @Path("/books/mapped.html")
   @Produces("text/html")
   public String getBooksMappedText() throws Exception
   {
      BookListing listing = getListing();
      JettisonMappedContext context = new JettisonMappedContext(BookListing.class);
      StringWriter writer = new StringWriter();
      Marshaller marshaller = context.createMarshaller();
      marshaller.marshal(listing, writer);
      return writer.toString();
   }
View Full Code Here

   @Path("books/mapped.html")
   @Produces("text/html")
   public String getBooksMappedText() throws Exception
   {
      BookListing listing = getListing();
      JettisonMappedContext context = new JettisonMappedContext(BookListing.class);
      StringWriter writer = new StringWriter();
      Marshaller marshaller = context.createMarshaller();
      marshaller.marshal(listing, writer);
      return writer.toString();
   }
View Full Code Here

   @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);
      }
   }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.plugins.providers.jaxb.json.JettisonMappedContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.