@Test public void properties() throws Exception { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setContextPath(CONTEXT_PATH); marshaller.setMarshallerProperties( Collections.<String, Object>singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE)); marshaller.afterPropertiesSet(); }
@Before public void setUp() { responseExtractor = new HttpMessageConverterExtractor<EmployeeList>(EmployeeList.class, restTemplate.getMessageConverters()); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); properties.put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setMarshallerProperties(properties); } /**
@Override public void afterPropertiesSet() throws Exception { final Map<String, Object> properties = new LinkedHashMap<>(); properties.put(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); properties.put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true); if (this.schemaLocation != null) { properties.put(javax.xml.bind.Marshaller.JAXB_SCHEMA_LOCATION, this.schemaLocation); } this.jaxb2Marshaller.setMarshallerProperties(properties); this.jaxb2Marshaller.afterPropertiesSet(); }
@Override public void afterPropertiesSet() throws Exception { final Map<String, Object> properties = new LinkedHashMap<>(); properties.put(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); properties.put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true); if (this.schemaLocation != null) { properties.put(javax.xml.bind.Marshaller.JAXB_SCHEMA_LOCATION, this.schemaLocation); } this.jaxb2Marshaller.setMarshallerProperties(properties); this.jaxb2Marshaller.afterPropertiesSet(); }
/** * jaxb2 marshaller. * * @return jaxb2 marshaller */ public static Jaxb2Marshaller jaxb2Marshaller() { final Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); // marshaller.setPackagesToScan(""); final Map<String, Object> properties = newLinkedHashMap(); properties.put(Marshaller.JAXB_ENCODING, Defaults.UTF_8.name()); properties.put(Marshaller.JAXB_FORMATTED_OUTPUT, FALSE); properties.put(Marshaller.JAXB_FRAGMENT, TRUE); marshaller.setMarshallerProperties(properties); 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; }
/** * 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; }
marshaller.setMarshallerProperties(marshallerProperties);
marshaller.setMarshallerProperties(marshallerProperties);
@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; }
final Map<String, Object> jaxbContextProps = new HashMap<String, Object>(); jaxbContextProps.put(JAXBContextProperties.OXM_METADATA_SOURCE, "binding.json"); jaxbContextProps.put(JAXBContextProperties.MEDIA_TYPE, "application/xml"); final Map<String, Object> marshallerProps = new HashMap<String, Object>(); marshallerProps.put(Marshaller.JAXB_FORMATTED_OUTPUT, true); final Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setLazyInit(true); marshaller.setClassesToBeBound(Pojo.class); marshaller.setJaxbContextProperties(jaxbContextProps); marshaller.setMarshallerProperties(marshallerProps); Pojo pojo = new Pojo(); pojo.set("message", "This is some message"); pojo.set("shouldValidate", "Yes"); pojo.set("buffer", "1000"); StringWriter writer = new StringWriter(); StreamResult streamResult = new StreamResult(writer); marshaller.marshal(pojo, streamResult); //System.out.println(writer.toString());
Map<String, Object> mp = new HashMap<String, Object>(); mp.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setMarshallerProperties(mp);
protected void initClient() { client = new WebServiceTemplate(); Jaxb2Marshaller m = new Jaxb2Marshaller(); m.setContextPaths( "net.exogeni.orca.manage.beans", "net.exogeni.orca.manage.proxies.soap.beans.actor", "net.exogeni.orca.manage.proxies.soap.beans.authority", //"net.exogeni.orca.manage.proxies.soap.beans.broker", "net.exogeni.orca.manage.proxies.soap.beans.clientactor", "net.exogeni.orca.manage.proxies.soap.beans.container", "net.exogeni.orca.manage.proxies.soap.beans.serveractor", "net.exogeni.orca.manage.proxies.soap.beans.servicemanager" ); Map<String, Object> mp = new HashMap<String, Object>(); mp.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setMarshallerProperties(mp); client.setMarshaller(m); client.setUnmarshaller(m); client.setDefaultUri(url); // for SSL connections installs all-trusting trust-manager NullHostVerifierMessageSender ss = new NullHostVerifierMessageSender(); ss.myInit(); client.setMessageSender(ss); }
@Override public void setConfiguration(XmlStringToObjectConfiguration configuration) { this.configuration = configuration; marshaller = new Jaxb2Marshaller(); if (StringUtils.isNotEmpty(configuration.getContextPath())){ marshaller.setContextPath(configuration.getContextPath()); } else if (ArrayUtils.isNotEmpty(configuration.getContextPaths())){ marshaller.setContextPaths(configuration.getContextPaths()); } else if (ArrayUtils.isNotEmpty(configuration.getClassesToBeBound())){ marshaller.setClassesToBeBound(configuration.getClassesToBeBound()); } marshaller.setUnmarshallerProperties(configuration.getUnmarshallerProperties()); marshaller.setMarshallerProperties(configuration.getMarshallerProperties()); if (configuration.getValidationEventHandler() != null) { marshaller.setValidationEventHandler(configuration.getValidationEventHandler()); } try { marshaller.afterPropertiesSet(); } catch (Exception e) { throw new ConfigurationException(e.getMessage()); } }
@Override public void setConfiguration(XmlToObjectConverterConfiguration configuration) { this.configuration = configuration; marshaller = new Jaxb2Marshaller(); if (StringUtils.isNotEmpty(configuration.getContextPath())){ marshaller.setContextPath(configuration.getContextPath()); } else if (ArrayUtils.isNotEmpty(configuration.getContextPaths())){ marshaller.setContextPaths(configuration.getContextPaths()); } else if (ArrayUtils.isNotEmpty(configuration.getClassesToBeBound())){ marshaller.setClassesToBeBound(configuration.getClassesToBeBound()); } marshaller.setUnmarshallerProperties(configuration.getUnmarshallerProperties()); marshaller.setMarshallerProperties(configuration.getMarshallerProperties()); if (configuration.getValidationEventHandler() != null) { marshaller.setValidationEventHandler(configuration.getValidationEventHandler()); } try { marshaller.afterPropertiesSet(); } catch (Exception e) { throw new ConfigurationException(e.getMessage()); } }