List of usage examples for javax.xml.bind JAXBElement JAXBElement
public JAXBElement(QName name, Class<T> declaredType, T value)
From source file:com.sportpm.mapper.JaxbMapper.java
/** * Java Collection->Xml with encoding, ?Root ElementCollection. *//*from w w w . j a v a 2 s . c o m*/ @SuppressWarnings("rawtypes") public static String toXml(Collection<?> root, String rootName, Class clazz, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(clazz, encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw Exceptions.unchecked(e); } }
From source file:cn.newtouch.util.utils.encode.JaxbBinder.java
/** * Java Object->Xml, ?Root ElementCollection. *//*from w w w. j a va2s. co m*/ @SuppressWarnings("unchecked") public String toXml(Collection root, String rootName, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:org.javelin.sws.ext.bind.SweJaxbContextFactoryTest.java
@Test public void defaultPackage() throws Exception { JAXBContext ctx = SweJaxbContextFactory.createContext("", null); // but we may marshal objects of built-in classes - XSD simple types ctx.createMarshaller().marshal(//from w ww.jav a2 s. co m new JAXBElement<String>(new QName("urn:test", "str"), String.class, "content"), System.out); }
From source file:$.JaxbMapper.java
/** * Java Collection->Xml with encoding, ?Root ElementCollection. *//*from w w w .j a va2 s . c om*/ public static String toXml(Collection<?> root, String rootName, Class clazz, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(clazz, encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw Exceptions.unchecked(e); } }
From source file:com.evolveum.midpoint.cli.common.ToolsUtils.java
public static void serializeObject(Object object, Writer writer) throws JAXBException { if (object == null) { return;// ww w .j av a2 s. c o m } Marshaller marshaller = JAXB_CONTEXT.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); if (object instanceof ObjectType) { object = new JAXBElement(C_OBJECT, Object.class, object); } marshaller.marshal(object, writer); }
From source file:net.cloudkit.enterprises.infrastructure.utilities.JaxbMapperHelper.java
/** * Java Collection->Xml with encoding, ?Root ElementCollection. *//*from ww w .j a v a 2s . c om*/ public static String toXml(Collection<?> root, String rootName, Class<?> clazz, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(clazz, encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw ExceptionHelper.unchecked(e); } }
From source file:org.javelin.sws.ext.bind.SweJaxbContextFactoryTest.java
@Test public void emptySetOfClassesForJaxbRi() throws Exception { JAXBContext ctx = JAXBContext.newInstance(); System.out.println(ctx.toString()); ctx.createMarshaller().marshal(// w ww . j ava2 s . c o m new JAXBElement<String>(new QName("urn:test", "str"), String.class, "content"), System.out); }
From source file:com.framework.infrastructure.mapper.JaxbMapper.java
/** * Java Collection->Xml with encoding, Root ElementCollection. *///from w w w .j a va2 s .c om public String toXml(Collection<?> root, String rootName, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw Exceptions.unchecked(e); } }
From source file:com.govsoft.framework.common.util.encode.JaxbBinder.java
/** * Java Object->Xml with encoding, ?Root ElementCollection. *//*from w w w . ja v a 2 s . c o m*/ public String toXml(Collection<?> root, String rootName, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:cn.hxh.springside.mapper.JaxbMapper.java
/** * Java Object->Xml with encoding, ?Root ElementCollection. *//*w w w . jav a 2s . c om*/ public String toXml(Collection<?> root, String rootName, String encoding) { try { CollectionWrapper wrapper = new CollectionWrapper(); wrapper.collection = root; JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper); StringWriter writer = new StringWriter(); createMarshaller(encoding).marshal(wrapperElement, writer); return writer.toString(); } catch (JAXBException e) { throw ExceptionUtils.unchecked(e); } }