@Before public void init() throws Exception { marshaller.setPackagesToScan(ClassUtils.getPackageName(GetCountryRequest.class)); marshaller.afterPropertiesSet(); }
@Test @SuppressWarnings("unchecked") public void unmarshalAnXmlReferingToAWrappedXmlElementDecl() throws Exception { // SPR-10714 unmarshaller = new Jaxb2Marshaller(); unmarshaller.setPackagesToScan(new String[] { "org.springframework.oxm.jaxb" }); unmarshaller.afterPropertiesSet(); Source source = new StreamSource(new StringReader( "<brand-airplane><name>test</name></brand-airplane>")); JAXBElement<Airplane> airplane = (JAXBElement<Airplane>) unmarshaller.unmarshal(source); assertEquals("Unmarshalling via explicit @XmlRegistry tag should return correct type", "test", airplane.getValue().getName()); }
@Test public void supportsPackagesToScan() throws Exception { marshaller = new Jaxb2Marshaller(); marshaller.setPackagesToScan(CONTEXT_PATH); marshaller.afterPropertiesSet(); testSupports(); }
@Test // SPR-10714 public void marshalAWrappedObjectHoldingAnXmlElementDeclElement() throws Exception { marshaller = new Jaxb2Marshaller(); marshaller.setPackagesToScan("org.springframework.oxm.jaxb"); marshaller.afterPropertiesSet(); Airplane airplane = new Airplane(); airplane.setName("test"); StringWriter writer = new StringWriter(); Result result = new StreamResult(writer); marshaller.marshal(airplane, result); DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE)); assertThat("Marshalling should use root Element", writer.toString(), isSimilarTo("<airplane><name>test</name></airplane>").withDifferenceEvaluator(ev)); }
/** * Enable pretty printing of returned XML */ @Bean public Jaxb2Marshaller marshaller() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); Map<String, Boolean> map = new HashMap<>(); map.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setMarshallerProperties(map); marshaller.setPackagesToScan("org.nzbhydra"); return marshaller; }
/** * Enable pretty printing of returned XML */ @Bean public Jaxb2Marshaller marshaller() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); Map<String, Boolean> map = new HashMap<>(); map.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setMarshallerProperties(map); marshaller.setPackagesToScan("org.nzbhydra.mockserver"); return marshaller; }
marshaller.setPackagesToScan("org.finra.herd.model.api.xml"); marshaller.setSchemas(resourceResolver.getResources("classpath:herd.xsd"));
marshaller.setPackagesToScan("org.finra.herd.model.api.xml"); marshaller.setSchemas(resourceResolver.getResources("classpath:herd.xsd"));
@Bean public Marshaller jaxbMarshaller() { Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); jaxb2Marshaller.setPackagesToScan(Names.class.getPackage().getName()); jaxb2Marshaller.setMarshallerProperties(Collections .singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true)); return jaxb2Marshaller; }
public XmlDeserializationTest() throws Exception { super(new TestData(URI.create("http://test-data/"), new DefaultModelFactory())); marshaller = new ApiJaxb2Marshaller(); marshaller.setPackagesToScan( "de.juplo.yourshouter.api.model.detached", "de.juplo.yourshouter.api.model.flat", "de.juplo.yourshouter.api.model.ref" ); marshaller.setSchemas( new ClassPathResource("/detached.xsd"), new ClassPathResource("/flat.xsd"), new ClassPathResource("/ref.xsd") ); marshaller.afterPropertiesSet(); }