FileOutputStream adrFile = null; try { adrFile = new FileOutputStream("test.xml"); JAXBContext ctx = JAXBContext.newInstance(RootElementClass.class); Marshaller ma = ctx.createMarshaller(); ma.marshal(..); } catch(IOException exc) { } catch(JAXBException exc) { } finally { }
package forum11221136; import java.io.File; import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Tests.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("src/forum11221136/input.xml"); Tests tests = (Tests) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(tests, System.out); } }
public String asString(JAXBContext pContext, Object pObject) throws JAXBException { java.io.StringWriter sw = new StringWriter(); Marshaller marshaller = pContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.marshal(pObject, sw); return sw.toString(); }
public static String serialize( StepMetaProps stepMetaProps ) { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { Marshaller marshalObj = JAXBContext.newInstance( StepMetaProps.class ).createMarshaller(); marshalObj.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true ); marshalObj.setProperty( Marshaller.JAXB_FRAGMENT, true ); marshalObj.marshal( stepMetaProps, baos ); return baos.toString( defaultCharset().name() ); } catch ( JAXBException | IOException e ) { throw new RuntimeException( e ); } }
/** * Dumps this model into XML. * * For debug only. * * TODO: not sure if this actually works. We don't really know what are T,C. */ public void dump( Result out ) throws JAXBException { JAXBContext context = JAXBContext.newInstance(this.getClass()); Marshaller m = context.createMarshaller(); m.marshal(this,out); } }
u.setProperty("eclipselink.media-type", mediaType.toString()); u.setProperty("eclipselink.json.include-root", false); return u.unmarshal(new StreamSource(entityStream), domainClass).getValue(); } catch(JAXBException jaxbException) { throw new WebApplicationException(jaxbException); try { Marshaller m = getJAXBContext(getDomainClass(genericType), mediaType).createMarshaller(); m.setProperty("eclipselink.media-type", mediaType.toString()); m.setProperty("eclipselink.json.include-root", false); m.marshal(object, entityStream); } catch(JAXBException jaxbException) { throw new WebApplicationException(jaxbException); JAXBContext jaxbContext; if(null == resolver || null == (jaxbContext = resolver.getContext(type))) { return JAXBContext.newInstance(type); } else { return jaxbContext;
Marshaller marshaller=jc.createMarshaller(); org.w3c.dom.Document doc = org.docx4j.XmlUtils.neww3cDomDocument(); marshaller.marshal(pkg, doc); Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); javax.xml.bind.util.JAXBResult result = new javax.xml.bind.util.JAXBResult(u );
u.setProperty("eclipselink.media-type", mediaType.toString()); u.setProperty("eclipselink.json.include-root", false); return u.unmarshal(new StreamSource(entityStream), domainClass).getValue(); } catch(JAXBException jaxbException) { throw new WebApplicationException(jaxbException); Class<?> domainClass = getDomainClass(genericType); Marshaller m = getJAXBContext(domainClass, mediaType).createMarshaller(); m.setProperty("eclipselink.media-type", mediaType.toString()); m.setProperty("eclipselink.json.include-root", false); m.marshal(object, entityStream); } catch(JAXBException jaxbException) { throw new WebApplicationException(jaxbException);
Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(new JAXBElement<MyClass>(new QName("uri","local"), MyClass.class, myClassInstance), System.out);
package nov18; import java.io.File; import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(FosterHome.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); FosterHome fosterHome = (FosterHome) unmarshaller.unmarshal(new File("src/nov18/input.xml")); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(fosterHome, System.out); } }
package forum7182533; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); root.setNumber(4); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); } }
@Override public synchronized void save(final E entity) { try { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(entity, file); } catch (final JAXBException ex) { throw new JobConsoleException(ex); } } }
JAXBContext jc = JAXBContext.newInstance(String.class, Bar.class); JAXBIntrospector introspector = jc.createJAXBIntrospector(); Marshaller marshaller = jc.createMarshaller(); if(null == introspector.getElementName(value)) { JAXBElement jaxbElement = new JAXBElement(new QName("ROOT"), Object.class, value); marshaller.marshal(jaxbElement, System.out); } else { marshaller.marshal(value, System.out);
public void marshal(final OutputStream os) throws JAXBException { final Marshaller marshaller = JAXB_CONTEXT.createMarshaller(); marshaller.marshal(this, os); }
/** * @param pmml model * @return model serialized as an XML document as a string */ public static String toString(PMML pmml) { try (StringWriter out = new StringWriter()) { // v JAXBUtil.marshalPMML but need to set compact, non-pretty output Marshaller marshaller = JAXBUtil.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); marshaller.marshal(pmml, new StreamResult(out)); return out.toString(); } catch (JAXBException | IOException e) { // IOException should not be possible; JAXBException would only happen with XML // config problems. throw new IllegalStateException(e); } }
public static void main(String[] args) throws JAXBException { TgCounterMapping tgmConfig = new TgCounterMapping("cpu", "cpu", "CPU"); JAXBContext jc = JAXBContext.newInstance(TgCounterMapping.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(tgmConfig, System.out); m.marshal(tgmConfig, new File("./temp.xml")); Unmarshaller um = jc.createUnmarshaller(); Object o = um.unmarshal(new File("./temp.xml")); System.out.println(o); } }
public static byte[] serialize(final StandardSnippet snippet) { try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final BufferedOutputStream bos = new BufferedOutputStream(baos); JAXBContext context = JAXBContext.newInstance(StandardSnippet.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(snippet, bos); bos.flush(); return baos.toByteArray(); } catch (final IOException | JAXBException e) { throw new FlowSerializationException(e); } } }
private void saveTenants(final Tenants tenants) throws JAXBException { final Marshaller marshaller = JAXB_TENANTS_CONTEXT.createMarshaller(); marshaller.setSchema(tenantsSchema); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(tenants, tenantsFile); }
final JAXBContext jaxbContext = JAXBContext.newInstance( ObjectFactory.class ); final Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal( report, reportFile );
@Override public RequestBody convert(final T value) throws IOException { Buffer buffer = new Buffer(); try { Marshaller marshaller = context.createMarshaller(); XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter( buffer.outputStream(), JaxbConverterFactory.XML.charset().name()); marshaller.marshal(value, xmlWriter); } catch (JAXBException | XMLStreamException e) { throw new RuntimeException(e); } return RequestBody.create(JaxbConverterFactory.XML, buffer.readByteString()); } }