/** * Marshal the given object into a string. * * @param object the root of content tree to be marshalled. * @return the XML representation of the given object. * @throws JAXBException if an error occurred during the marshalling. */ public static String marshal(final Object object) throws JAXBException { ensureNonNull("object", object); final StringWriter output = new StringWriter(); final MarshallerPool pool = getPool(); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.marshal(object, output); pool.recycle(marshaller); return output.toString(); }
/** * Marshal the given object into a string. * * @param object the root of content tree to be marshalled. * @return the XML representation of the given object. * @throws JAXBException if an error occurred during the marshalling. */ public static String marshal(final Object object) throws JAXBException { ensureNonNull("object", object); final StringWriter output = new StringWriter(); final MarshallerPool pool = getPool(); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.marshal(object, output); pool.recycle(marshaller); return output.toString(); }
/** * Unmarshal an object from the given stream. * * @param input the stream from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final InputStream input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given URL. * * @param input the URL from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final URL input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given file. * * @param input the file from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final File input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given stream. * * @param input the stream from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final InputStream input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given URL. * * @param input the URL from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final URL input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given file. * * @param input the file from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final File input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
@After public void tearDown() { if (marshaller != null) { pool.recycle(marshaller); } }
@After public void tearDown() { if (unmarshaller != null) { pool.recycle(unmarshaller); } }
/** * Marshal the given object into a stream. * * @param object the root of content tree to be marshalled. * @param output the stream where to write. * @throws JAXBException if an error occurred during the marshalling. */ public static void marshal(final Object object, final OutputStream output) throws JAXBException { ensureNonNull("object", object); ensureNonNull("output", output); final MarshallerPool pool = getPool(); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.marshal(object, output); pool.recycle(marshaller); }
/** * Marshal the given object into a stream. * * @param object the root of content tree to be marshalled. * @param output the stream where to write. * @throws JAXBException if an error occurred during the marshalling. */ public static void marshal(final Object object, final OutputStream output) throws JAXBException { ensureNonNull("object", object); ensureNonNull("output", output); final MarshallerPool pool = getPool(); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.marshal(object, output); pool.recycle(marshaller); }
/** * Marshal the given object into a file. * * @param object the root of content tree to be marshalled. * @param output the file to be written. * @throws JAXBException if an error occurred during the marshalling. */ public static void marshal(final Object object, final File output) throws JAXBException { ensureNonNull("object", object); ensureNonNull("output", output); final MarshallerPool pool = getPool(); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.marshal(object, output); pool.recycle(marshaller); }
/** * Marshal the given object into a file. * * @param object the root of content tree to be marshalled. * @param output the file to be written. * @throws JAXBException if an error occurred during the marshalling. */ public static void marshal(final Object object, final File output) throws JAXBException { ensureNonNull("object", object); ensureNonNull("output", output); final MarshallerPool pool = getPool(); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.marshal(object, output); pool.recycle(marshaller); }
/** * Converse of {@link #marshal(GenericName)}. */ private GenericName unmarshal(final String xml) throws JAXBException { final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object value = unmarshal(unmarshaller, xml); pool.recycle(unmarshaller); return ((IdentifiedObjectMock) value).alias; }
/** * Returns the XML representation of the given name, wrapped * in a mock {@code <gml:IO_IdentifiedObject>} element. */ private String marshal(final GenericName name) throws JAXBException { if (pool == null) { pool = new MarshallerPool(JAXBContext.newInstance(IdentifiedObjectMock.class), Collections.singletonMap(XML.LENIENT_UNMARSHAL, Boolean.TRUE)); } final Marshaller marshaller = pool.acquireMarshaller(); marshaller.setProperty(XML.METADATA_VERSION, VERSION_2007); final String xml = marshal(marshaller, new IdentifiedObjectMock(null, name)); pool.recycle(marshaller); return xml; }
/** * Tests marshalling in the GML 3.1 namespace. * * @throws JAXBException if an error occurred during marshalling. */ @Test @DependsOnMethod("testMarshall") public void testMarshallGML31() throws JAXBException { final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(PrimeMeridianMock.GREENWICH); final MarshallerPool pool = getMarshallerPool(); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0); final String xml = marshal(marshaller, pm); pool.recycle(marshaller); assertXmlEquals(getGreenwichXml(LegacyNamespaces.GML), xml, "xmlns:*", "xsi:schemaLocation"); }
/** * Tests marshalling in the GML 3.1 namespace. * * @throws JAXBException if an error occurred during unmarshalling. */ @Test @DependsOnMethod("testUnmarshall") public void testUnarshallGML31() throws JAXBException { final MarshallerPool pool = getMarshallerPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); unmarshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0); final DefaultPrimeMeridian pm = (DefaultPrimeMeridian) unmarshal(unmarshaller, getGreenwichXml(LegacyNamespaces.GML)); pool.recycle(unmarshaller); assertIsGreenwich(pm); }