List of utility methods to do XML JAXB Context
JAXBContext | getJAXBContext(String namespaces) get JAXB Context jaxbContext = JAXBContext.newInstance("com.sun.xml.wss.saml.internal.saml20.jaxb20" + ":" + namespaces); return jaxbContext; |
JAXBContext | getJAXBContext(String packagePrefix) get JAXB Context return JAXBContext.newInstance(packagePrefix);
|
JAXBContext | getJAXBContextForWebService(Class> webService) get JAXB Context For Web Service if (!hasWebServiceAnnotation(webService)) { throw new IllegalArgumentException("no webservice class"); Set<Class<?>> classes = new HashSet<>(); collect(webService, classes); try { Class[] classesToBeBound = classes.stream() .filter(clazz -> clazz.getDeclaredAnnotation(XmlRootElement.class) != null) ... |
JAXBContext | getRequestContext() get Request Context try { if (jaxbRequestContext == null) jaxbRequestContext = JAXBContext.newInstance("flowers.salta.resource.request"); } catch (JAXBException je) { je.printStackTrace(); return jaxbRequestContext; |
JAXBContext | getRightsContext() get Rights Context return JAXBContext.newInstance("eu.prestoprime.model.ext.rights"); |
boolean | isElement(String contextPath, Object object) is Element try { return object != null && getJAXBContext(contextPath).createJAXBIntrospector().isElement(object); } catch (JAXBException ex) { throw new RuntimeException(ex); |
T | parseXMLFile(String fileName, String contextPath) Parses the given XML file. FileReader fileReader = new FileReader(fileName); JAXBContext jc = JAXBContext.newInstance(contextPath); Unmarshaller u = jc.createUnmarshaller(); @SuppressWarnings("unchecked") T xRoot = ((JAXBElement<T>) u.unmarshal(fileReader)).getValue(); return xRoot; |
String | toString(JAXBContext context, Object object) to String final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); final StringWriter sw = new StringWriter(); marshaller.marshal(object, sw); return sw.toString(); |
String | toXML(JAXBContext context, T obj) Converts this response object to its XML representation unsing JAXB. StringWriter sw = new StringWriter(); Marshaller m = context.createMarshaller(); m.setProperty(JAXB_FORMATTED_OUTPUT, true); m.marshal(obj, sw); return sw.toString(); |