List of usage examples for javax.xml.bind Marshaller JAXB_ENCODING
String JAXB_ENCODING
To view the source code for javax.xml.bind Marshaller JAXB_ENCODING.
Click Source Link
From source file:org.apache.nifi.cluster.flow.impl.DataFlowDaoImpl.java
private void writeClusterMetadata(final ClusterMetadata clusterMetadata, final OutputStream os) throws IOException, JAXBException { // write cluster metadata to output stream final Marshaller marshaller = ClusterMetadata.jaxbCtx.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.marshal(clusterMetadata, os); }
From source file:org.artificer.server.atom.workspaces.AbstractWorkspaceTest.java
/** * Marshalls the app service to XML.//from www . j a va2 s. c o m * @param appService */ public static String marshall(AppService appService) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(AppService.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter writer = new StringWriter(); JAXBElement<AppService> element = new JAXBElement<AppService>(new QName("", "app:service", "app"), AppService.class, appService); marshaller.marshal(element, writer); return writer.toString(); }
From source file:org.betaconceptframework.astroboa.model.jaxb.CmsEntitySerialization.java
public Marshaller createMarshaller(ResourceRepresentationType<?> resourceRepresentationType, boolean prettyPrint) throws JAXBException { boolean jsonResourceRepresentationType = resourceRepresentationType != null && ResourceRepresentationType.JSON.equals(resourceRepresentationType); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setListener(new AstroboaMarshalListener(jsonResourceRepresentationType)); if (jsonResourceRepresentationType) { LocalizationAdapter localizationAdapter = new LocalizationAdapter(); localizationAdapter.useJsonVersion(); marshaller.setAdapter(localizationAdapter); }// w ww. j a v a2 s . c o m marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, prettyPrint); return new AstroboaMarshaller(marshaller, resourceRepresentationType); }
From source file:org.codice.ddf.spatial.kml.transformer.KMLTransformerImpl.java
private String marshalKml(Kml kmlResult) { String kmlResultString = null; StringWriter writer = new StringWriter(); try {// ww w. j a v a2 s. c o m Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); marshaller.setProperty(Marshaller.JAXB_ENCODING, UTF_8); marshaller.marshal(kmlResult, writer); } catch (JAXBException e) { LOGGER.warn("Failed to marshal KML: ", e); } kmlResultString = writer.toString(); return kmlResultString; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
/** Tests to see that JAXB configuration is working */ @Test//from w w w. j a va2s. c o m public void testMarshallDescribeRecord() { DescribeRecordResponseType response = new DescribeRecordResponseType(); List<SchemaComponentType> schemas = new ArrayList<>(); SchemaComponentType schemaComponentType = new SchemaComponentType(); schemas.add(schemaComponentType); response.setSchemaComponent(schemas); JAXBContext context; try { context = JAXBContext .newInstance("net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter sw = new StringWriter(); JAXBElement<DescribeRecordResponseType> wrappedResponse = new JAXBElement<>(cswQnameOutPutSchema, DescribeRecordResponseType.class, response); marshaller.marshal(wrappedResponse, sw); LOGGER.info("Response: {}", sw.toString()); } catch (JAXBException e) { fail("Could not marshall message, Error: " + e.getMessage()); } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java
private void verifyMarshalResponse(TransactionResponseType response, String contextPath, QName qName) { // Verify the response will marshal try {/* w w w .j ava 2 s . co m*/ JAXBContext context = JAXBContext.newInstance(contextPath); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter sw = new StringWriter(); JAXBElement<TransactionResponseType> wrappedResponse = new JAXBElement<>(qName, TransactionResponseType.class, response); marshaller.marshal(wrappedResponse, sw); LOGGER.info("Response: {}", sw.toString()); } catch (JAXBException e) { fail("Could not marshal message, Error: " + e.getMessage()); } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
/** * Tests to see that JAXB configuration is working *//*from w ww. ja v a 2s. c om*/ @Test public void testMarshallDescribeRecord() { DescribeRecordResponseType response = new DescribeRecordResponseType(); List<SchemaComponentType> schemas = new ArrayList<>(); SchemaComponentType schemaComponentType = new SchemaComponentType(); schemas.add(schemaComponentType); response.setSchemaComponent(schemas); JAXBContext context; try { context = JAXBContext .newInstance("net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter sw = new StringWriter(); JAXBElement<DescribeRecordResponseType> wrappedResponse = new JAXBElement<>(cswQnameOutPutSchema, DescribeRecordResponseType.class, response); marshaller.marshal(wrappedResponse, sw); LOGGER.info("\nResponse\n" + sw.toString() + "\n\n"); } catch (JAXBException e) { fail("Could not marshall message, Error: " + e.getMessage()); } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
private void verifyMarshalResponse(TransactionResponseType response, String contextPath, QName qName) { // Verify the response will marshal try {// w w w . j av a 2 s . c o m JAXBContext context = JAXBContext.newInstance(contextPath); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter sw = new StringWriter(); JAXBElement<TransactionResponseType> wrappedResponse = new JAXBElement<>(qName, TransactionResponseType.class, response); marshaller.marshal(wrappedResponse, sw); LOGGER.info("\nResponse\n" + sw.toString() + "\n\n"); } catch (JAXBException e) { fail("Could not marshal message, Error: " + e.getMessage()); } }
From source file:org.drools.semantics.lang.dl.DL_9_CompilationTest.java
private void checkJaxbRefresh(Object obj, ClassLoader urlKL) { try {/* w w w.j a va 2s .c o m*/ JAXBContext jaxbContext; jaxbContext = JAXBContext.newInstance(obj.getClass().getPackage().getName(), urlKL); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter sw = new StringWriter(); marshaller.marshal(obj, sw); System.out.println(sw.toString()); jaxbContext = JAXBContext.newInstance(obj.getClass().getPackage().getName(), urlKL); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Marshaller marshaller2 = jaxbContext.createMarshaller(); marshaller2.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller2.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Object clone = unmarshaller.unmarshal(new StringReader(sw.toString())); StringWriter sw2 = new StringWriter(); marshaller2.marshal(clone, sw2); System.err.println(sw2.toString()); assertEquals(sw.toString(), sw2.toString()); } catch (PropertyException e) { e.printStackTrace(); fail(e.getMessage()); } catch (JAXBException e) { fail(e.getMessage()); } }
From source file:org.eclipsetrader.internal.brokers.paper.PaperBroker.java
public void save(File file) throws JAXBException, IOException { if (file.exists()) { file.delete();//from w w w.j a v a 2 s.c o m } JAXBContext jaxbContext = JAXBContext.newInstance(OrderMonitor[].class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setEventHandler(new ValidationEventHandler() { @Override public boolean handleEvent(ValidationEvent event) { Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, 0, "Error validating XML: " + event.getMessage(), null); //$NON-NLS-1$ Activator.log(status); return true; } }); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, System.getProperty("file.encoding")); //$NON-NLS-1$ OrderMonitor[] elements = pendingOrders.toArray(new OrderMonitor[pendingOrders.size()]); JAXBElement<OrderMonitor[]> element = new JAXBElement<OrderMonitor[]>(new QName("list"), OrderMonitor[].class, elements); marshaller.marshal(element, new FileWriter(file)); }