Class MarshallerMethods
- java.lang.Object
- 
- io.toro.martini.MarshallerMethods
 
- 
 public final class MarshallerMethods extends Object 
- 
- 
Constructor SummaryConstructors Constructor Description MarshallerMethods(io.toro.martini.xml.XMLObjectConverter xmlObjectConverter)
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static StringasJSON(Object o)Marshal an object into a JSON string.static StringasXML(Object o)Marshal an object into a JSON string.static <T> TfromJSON(File jsonFile, Class<T> returnType)Unmarshal the JSON content of a file to an instance of the provided type.static <T> TfromJSON(InputStream jsonInputStream, Class<T> returnType)Unmarshal the JSON content of a stream to an instance of the provided type.static <T> TfromJSON(Reader jsonReader, Class<T> returnType)Unmarshal the JSON content of a reader to an instance of the provided type.static <T> TfromJSON(String jsonString, Class<T> returnType)Unmarshal a JSON string to an instance of the provided type.static <T> TfromJSON(URL jsonURL, Class<T> returnType)Unmarshal the JSON document located in the provided URL, to an instance of the provided type.static <T> TfromXML(File xmlFile, Class<T> returnType)Unmarshal the XML content of a file to an instance of the provided type.static <T> TfromXML(InputStream xmlInputStream, Class<T> returnType)Unmarshal the XML content of a stream to an instance of the provided type.static <T> TfromXML(Reader xmlReader, Class<T> returnType)Unmarshal the XML content of a reader to an instance of the provided type.static <T> TfromXML(String xmlString, Class<T> returnType)Unmarshal an XML string to an instance of the provided type.static <T> TfromXML(URL xmlURL, Class<T> returnType)Unmarshal the XML document located in the provided URL, to an instance of the provided type.
 
- 
- 
- 
Constructor Detail- 
MarshallerMethods@Autowired public MarshallerMethods(io.toro.martini.xml.XMLObjectConverter xmlObjectConverter) 
 
- 
 - 
Method Detail- 
asJSONpublic static String asJSON(Object o) Marshal an object into a JSON string. Example usage: Person person = new Person( firstname: 'John', lastname: 'Doe' ) String json = person.asJSON() - Parameters:
- o- the object to be marshalled
- Returns:
- the pretty-printed JSON string representation of the provided object
- Since:
- 1.0
 
 - 
asXMLpublic static String asXML(Object o) Marshal an object into a JSON string. Example usage: Person person = new Person( firstname: 'John', lastname: 'Doe' ) String json = person.asXML() - Parameters:
- o- the object to be marshalled
- Returns:
- the pretty-printed XML string representation of the provided object
- Since:
- 1.0
 
 - 
fromXMLpublic static <T> T fromXML(String xmlString, Class<T> returnType) Unmarshal an XML string to an instance of the provided type. Example usage: String xml = ... Person person = xml.fromXML( Person.class ) - Parameters:
- xmlString- the XML string to unmarshal
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the provided XML string
- Since:
- 1.0
 
 - 
fromXMLpublic static <T> T fromXML(File xmlFile, Class<T> returnType) Unmarshal the XML content of a file to an instance of the provided type. Example usage: File xml = new File( 'path/to/person.xml' ) Person person = xml.fromXML( Person.class ) - Parameters:
- xmlFile- the file containing the XML string to unmarshal
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the content of the provided XML file
- Since:
- 1.0
 
 - 
fromXMLpublic static <T> T fromXML(InputStream xmlInputStream, Class<T> returnType) Unmarshal the XML content of a stream to an instance of the provided type. Example usage: try ( InputStream xml = ... ) { Person person = xml.fromXML( Person.class ) }- Parameters:
- xmlInputStream- the stream containing the XML string to unmarshal
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the content of the provided XML input stream
- Since:
- 1.0
 
 - 
fromXMLpublic static <T> T fromXML(Reader xmlReader, Class<T> returnType) Unmarshal the XML content of a reader to an instance of the provided type. Example usage: Reader xml = ... Person person = xml.fromXML( Person.class ) - Parameters:
- xmlReader- the reader containing the XML string to unmarshal
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the content of the provided XML reader
- Since:
- 1.0
 
 - 
fromXMLpublic static <T> T fromXML(URL xmlURL, Class<T> returnType) Unmarshal the XML document located in the provided URL, to an instance of the provided type. Example usage: URL xml = new URL( 'https://www.w3schools.com/xml/plant_catalog.xml' ) Person person = xml.fromXML( Person.class ) - Parameters:
- xmlURL- the URL pointing to the XML document which will be unmarshalled
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the content of the provided XML document
- Since:
- 1.0
 
 - 
fromJSONpublic static <T> T fromJSON(String jsonString, Class<T> returnType) Unmarshal a JSON string to an instance of the provided type. Example usage: String json = ... Person person = json.fromJSON( Person.class ) - Parameters:
- jsonString- the JSON string to unmarshal
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the provided JSON string
- Since:
- 1.0
 
 - 
fromJSONpublic static <T> T fromJSON(File jsonFile, Class<T> returnType) Unmarshal the JSON content of a file to an instance of the provided type. Example usage: File json = new File( 'path/to/person.json' ) Person person = json.fromJSON( Person.class ) - Parameters:
- jsonFile- the file containing the JSON string to unmarshal
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the content of the provided JSON file
- Since:
- 1.0
 
 - 
fromJSONpublic static <T> T fromJSON(InputStream jsonInputStream, Class<T> returnType) Unmarshal the JSON content of a stream to an instance of the provided type. Example usage: try ( InputStream json = ... ) { Person person = json.fromJSON( Person.class ) }- Parameters:
- jsonInputStream- the stream containing the JSON string to unmarshal
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the content of the provided JSON input stream
- Since:
- 1.0
 
 - 
fromJSONpublic static <T> T fromJSON(Reader jsonReader, Class<T> returnType) Unmarshal the JSON content of a reader to an instance of the provided type. Example usage: Reader json = ... Person person = json.fromJSON( Person.class ) - Parameters:
- jsonReader- the reader containing the JSON string to unmarshal
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the content of the provided JSON reader
- Since:
- 1.0
 
 - 
fromJSONpublic static <T> T fromJSON(URL jsonURL, Class<T> returnType) Unmarshal the JSON document located in the provided URL, to an instance of the provided type. Example usage: URL json = new URL( 'https://api.github.com/users/me/repos' ) Person person = json.fromJSON( Person.class ) - Parameters:
- jsonURL- the URL pointing to the JSON document which will be unmarshalled
- returnType- the type of object where unmarshalled data shall be put into
- Returns:
- an instance of the specified class, whose data is based on the content of the provided JSON document
- Since:
- 1.0
 
 
- 
 
-