Package net.authorize.util
Class XmlUtility
- java.lang.Object
-
- net.authorize.util.XmlUtility
-
public final class XmlUtility extends Object
Helper methods for serializing and de-serializing to XML using JAXB- Author:
- ramittal
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Serializable>
Tcreate(String xml, Class<T> classType)Helper method to de-serialize XML to an object.static StringdescapeStringForXml(String valueToDeserialize)Helper method to decode a string from XML string Returns the same string if null or emptystatic StringescapeStringForXml(String valueToSerialize)Helper method to encode a string to XML Returns the same string if null or emptystatic StringgetRootElementXml(String xmlString)Removes the XML prologuestatic <T extends Serializable>
StringgetRootElementXml(T entity)Removes the XML prologuestatic <T extends Serializable>
StringgetXml(T entity)Helper method to serialize an object to XML.
-
-
-
Method Detail
-
getXml
public static <T extends Serializable> String getXml(T entity) throws IOException, jakarta.xml.bind.JAXBException
Helper method to serialize an object to XML. Requires object to be Serializable- Type Parameters:
T- class that implements Serializable- Parameters:
entity- Object to serialize- Returns:
- String XML representation of object
- Throws:
IOException- if errors during serializationjakarta.xml.bind.JAXBException- if errors during serialization
-
create
public static <T extends Serializable> T create(String xml, Class<T> classType) throws ParserConfigurationException, SAXException, jakarta.xml.bind.JAXBException
Helper method to de-serialize XML to an object. Requires object to be Serializable- Type Parameters:
T- class that implements Serializable- Parameters:
xml- object serialized into valid XMLclassType- Class Type of the object to be de-serialized into- Returns:
- T De-serialized object
- Throws:
ParserConfigurationExceptionSAXExceptionjakarta.xml.bind.JAXBException
-
escapeStringForXml
public static String escapeStringForXml(String valueToSerialize)
Helper method to encode a string to XML Returns the same string if null or empty- Parameters:
valueToSerialize- string value to encode into xml- Returns:
- xml encoded string
-
descapeStringForXml
public static String descapeStringForXml(String valueToDeserialize)
Helper method to decode a string from XML string Returns the same string if null or empty- Parameters:
valueToDeserialize- string value to decode from xml- Returns:
- string decoded from xml
-
getRootElementXml
public static <T extends Serializable> String getRootElementXml(T entity)
Removes the XML prologue- Parameters:
entity- object to remove prologue- Returns:
- String String XML representation of root element xml without prologue
-
-