static Unmarshaller getUnmarsheller() throws JAXBException { if (versionClusterUnmarshaller == null) { RemoteAdmin.versionClusterUnmarshaller = JAXBContext.newInstance( StorageClusterVersionModel.class).createUnmarshaller(); } return RemoteAdmin.versionClusterUnmarshaller; }
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); } }
@Override @SneakyThrows public FillerRuleDefinitionEntity load(final String fillerRuleDefinitionFile) { InputStream inputStream = FillerRuleDefinitionEntityLoader.class.getClassLoader().getResourceAsStream(fillerRuleDefinitionFile); Preconditions.checkNotNull(inputStream, "Cannot load SQL filler rule definition file :%s, ", fillerRuleDefinitionFile); return (FillerRuleDefinitionEntity) JAXBContext.newInstance(FillerRuleDefinitionEntity.class).createUnmarshaller().unmarshal(inputStream); } }
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 ); } }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled); extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, ""); TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(conf); context = JAXBContext.newInstance( CellModel.class, CellSetModel.class, RowModel.class); marshaller = context.createMarshaller(); unmarshaller = context.createUnmarshaller(); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); Admin admin = TEST_UTIL.getAdmin(); if (admin.tableExists(TABLE)) { return; } HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); }
/** * 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); } }
public JaxbSolutionFileIO(Class... jaxbAnnotatedClasses) { try { JAXBContext jaxbContext = JAXBContext.newInstance(jaxbAnnotatedClasses); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException e) { throw new IllegalArgumentException("JAXB creation for classes (" + Arrays.toString(jaxbAnnotatedClasses) + ") has failed.", e); } }
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;
testContext = JAXBContext.newInstance("org.docx4j.relationships",classLoader ); Marshaller m=testContext.createMarshaller(); m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", c.newInstance() ); log.info("Using NamespacePrefixMapperRelationshipsPartSunInternal, which is suitable for Java 6"); prefixMapperRels = c.newInstance();
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); } }
@Override @SneakyThrows public SQLStatementRuleDefinitionEntity load(final String sqlStatementRuleDefinitionFile) { InputStream inputStream = SQLStatementRuleDefinitionEntityLoader.class.getClassLoader().getResourceAsStream(sqlStatementRuleDefinitionFile); Preconditions.checkNotNull(inputStream, "Cannot load SQL statement rule definition file :%s, ", sqlStatementRuleDefinitionFile); return (SQLStatementRuleDefinitionEntity) JAXBContext.newInstance(SQLStatementRuleDefinitionEntity.class).createUnmarshaller().unmarshal(inputStream); } }
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); } }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(conf); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); context = JAXBContext.newInstance( CellModel.class, CellSetModel.class, RowModel.class, ScannerModel.class); marshaller = context.createMarshaller(); unmarshaller = context.createUnmarshaller(); Admin admin = TEST_UTIL.getAdmin(); if (admin.tableExists(TABLE)) { return; } HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); expectedRows1 = insertData(TEST_UTIL.getConfiguration(), TABLE, COLUMN_1, 1.0); expectedRows2 = insertData(TEST_UTIL.getConfiguration(), TABLE, COLUMN_2, 0.5); htd = new HTableDescriptor(TABLE_TO_BE_DISABLED); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); }
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 JAXBService(Class<?>... xsdRootClasses) { try { JAXBContext jaxbContext = JAXBContext.newInstance(xsdRootClasses); marshaller = jaxbContext.createMarshaller(); unmarshaller = jaxbContext.createUnmarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); String schemas = Arrays.stream(xsdRootClasses).map(c -> { XSDRootElement element = c.getAnnotation(XSDRootElement.class); if (element != null && StringUtils.isNotEmpty(element.namespace()) && StringUtils.isNotEmpty(element.schemaLocation())) { return (element.namespace() + " " + element.schemaLocation()); } return null; }).filter(Objects::nonNull).collect(Collectors.joining(" ")); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemas); // use a custom Filter so that we can unmarshall older namespace or no namespace xml XMLReader reader = XMLReaderFactory.createXMLReader(); nameSpaceFilter = new NameSpaceFilter(); nameSpaceFilter.setParent(reader); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
testContext = JAXBContext.newInstance("org.docx4j.relationships",classLoader ); Marshaller m=testContext.createMarshaller(); m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", c.newInstance() ); log.info("Using NamespacePrefixMapperSunInternal, which is suitable for Java 6"); prefixMapper = c.newInstance();
import java.io.InputStream; import java.net.URL; import javax.xml.bind.*; import javax.xml.transform.stream.StreamSource; import org.w3._2005.atom.FeedType; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance("org.w3._2005.atom"); Unmarshaller unmarshaller = jc.createUnmarshaller(); URL url = new URL("http://bdoughan.blogspot.com/atom.xml"); InputStream xml = url.openStream(); JAXBElement<feedtype> feed = unmarshaller.unmarshal(new StreamSource(xml), FeedType.class); xml.close(); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(feed, System.out); } }
@Override @SneakyThrows public ExtractorRuleDefinitionEntity load(final String extractorRuleDefinitionFile) { InputStream inputStream = ExtractorRuleDefinitionEntityLoader.class.getClassLoader().getResourceAsStream(extractorRuleDefinitionFile); Preconditions.checkNotNull(inputStream, "Cannot load extractor rule definition file :%s, ", extractorRuleDefinitionFile); return (ExtractorRuleDefinitionEntity) JAXBContext.newInstance(ExtractorRuleDefinitionEntity.class).createUnmarshaller().unmarshal(inputStream); } }
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); } } }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); TEST_UTIL.startMiniCluster(3); REST_TEST_UTIL.startServletContainer(conf); context = JAXBContext.newInstance( CellModel.class, CellSetModel.class, RowModel.class); xmlMarshaller = context.createMarshaller(); xmlUnmarshaller = context.createUnmarshaller(); jsonMapper = new JacksonJaxbJsonProvider() .locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); }