@Component public class XmlHelper extends Object
| Constructor and Description |
|---|
XmlHelper() |
| Modifier and Type | Method and Description |
|---|---|
static String |
createPrettyPrint(String input)
Reformat xml string to indented "pretty printed" view
|
String |
objectToXml(Object obj)
Returns XML representation of the object.
|
String |
objectToXml(Object obj,
boolean formatted)
Returns XML representation of the object using the herd custom character escape handler.
|
<T> T |
unmarshallXmlToObject(Class<T> classType,
String xmlString)
Unmarshalls the xml into JAXB object.
|
public String objectToXml(Object obj) throws JAXBException
obj - the Java object to be serializedJAXBException - if a JAXB error occurred.public String objectToXml(Object obj, boolean formatted) throws JAXBException
obj - the Java object to be serializedformatted - specifies whether or not the marshalled XML data is formatted with line feeds and indentationJAXBException - if a JAXB error occurred.public <T> T unmarshallXmlToObject(Class<T> classType, String xmlString) throws JAXBException
T - the class type.classType - the class type of JAXB elementxmlString - the xml stringJAXBException - if there is an error in unmarshallingpublic static String createPrettyPrint(String input) throws TransformerFactoryConfigurationError, TransformerException
input - the xml string to be reformattedTransformerFactoryConfigurationError - in case of TransformerFactory configuration error
or if the implementation is not available or cannot be instantiated.TransformerException - when unable to perform indent transformationCopyright © 2021. All rights reserved.