Package javax.xml.bind

Examples of javax.xml.bind.JAXBContext.createMarshaller()


//        Unmarshaller unmarshaller = new UnmarshallerImpl(Collections.<JAXBMarshaller>singleton(EjbJarJaxB.INSTANCE));
//        Marshaller marshaller = new MarshallerImpl(Collections.<JAXBMarshaller>singleton(EjbJarJaxB.INSTANCE));
        JAXBContext ctx = JAXBContextFactory.newInstance(EjbJar.class);
        Unmarshaller unmarshaller = ctx.createUnmarshaller();
        Marshaller marshaller = ctx.createMarshaller();

        NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
        unmarshaller.setEventHandler(new TestValidationEventHandler());
View Full Code Here


        SAXSource source = new SAXSource(xmlFilter, new InputSource(new ByteArrayInputStream(expected.getBytes())));

        Object object = unmarshaller.unmarshal(source);

        Marshaller marshaller = ctx.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        marshaller.marshal(object, baos);
View Full Code Here

    }

    protected final Marshaller getMarshaller(Class<?> type, MediaType mediaType)
        throws JAXBException {
        JAXBContext context = getContext(type, mediaType);
        return context.createMarshaller();
    }

    protected boolean isSupportedMediaType(MediaType mediaType) {
        return MediaTypeUtils.isXmlType(mediaType);
    }
View Full Code Here

            try {
                return parentTypeConverter.convertTo(type, source);
            } catch (NoTypeConversionAvailableException e) {
                // lets try a stream
                StringWriter buffer = new StringWriter();
                Marshaller marshaller = context.createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, isPrettyPrint() ? Boolean.TRUE : Boolean.FALSE);
                marshaller.marshal(value, buffer);
                return parentTypeConverter.convertTo(type, buffer.toString());
            }
        }
View Full Code Here

                JAXBElement element = (JAXBElement) object;
                type = element.getValue().getClass();
            }

            JAXBContext ctx = JAXBContext.newInstance(type);
            Marshaller marshaller = ctx.createMarshaller();

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            marshaller.marshal(object, baos);

            String xml = new String(baos.toByteArray());
View Full Code Here

        e.setTitle(b.getName());
        e.setId(Long.toString(b.getId()));
       
       
        StringWriter writer = new StringWriter();
        jc.createMarshaller().marshal(b, writer);
       
        Content ct = factory.newContent(Content.Type.XML);
        ct.setValue(writer.toString());
        e.setContentElement(ct);
        return e;
View Full Code Here

    CreditCard07 creditCard = new CreditCard07("1234", "12/09", 6398, "Visa");
    StringWriter writer = new StringWriter();

    JAXBContext context = JAXBContext.newInstance(CreditCard07.class);
    Marshaller m = context.createMarshaller();
    m.marshal(creditCard, writer);

    System.out.println(writer.toString());
  }
}
View Full Code Here

    CreditCard11 creditCard = new CreditCard11("12345678", "10/14", 566, "Visa");

    StringWriter writer = new StringWriter();
    JAXBContext context = JAXBContext.newInstance(CreditCard11.class);
    Marshaller m = context.createMarshaller();
    m.marshal(creditCard, writer);

    System.out.println(writer);

    assertEquals(creditCardXML, writer.toString());
View Full Code Here

        }
        // create a JAXBContext for the PMML class
        JAXBContext ctx = null;
        try {
            ctx = JAXBContext.newInstance(PMML.class);
            Marshaller marshaller = ctx.createMarshaller();
            // the property JAXB_FORMATTED_OUTPUT specifies whether or not the
            // marshalled XML data is formatted with linefeeds and indentation
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            // marshal the data in the Java content tree
            StringWriter stringWriter = new StringWriter();
View Full Code Here

      MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException
   {
      try
      {
         JAXBContext jaxbctx = getJAXBContext(type, mediaType);
         Marshaller m = jaxbctx.createMarshaller();
         // Must respect application specified character set.
         String charset = mediaType.getParameters().get("charset");
         if (charset != null)
            m.setProperty(Marshaller.JAXB_ENCODING, charset);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.