public final class MarshallerMethods extends Object
Constructor and Description |
---|
MarshallerMethods(io.toro.martini.xml.XMLObjectConverter xmlObjectConverter) |
Modifier and Type | Method and Description |
---|---|
static String |
asJSON(Object o)
Marshal an object into a JSON string.
|
static String |
asXML(Object o)
Marshal an object into a JSON string.
|
static <T> T |
fromJSON(File jsonFile,
Class<T> returnType)
Unmarshal the JSON content of a file to an instance of the provided type.
|
static <T> T |
fromJSON(InputStream jsonInputStream,
Class<T> returnType)
Unmarshal the JSON content of a stream to an instance of the provided type.
|
static <T> T |
fromJSON(Reader jsonReader,
Class<T> returnType)
Unmarshal the JSON content of a reader to an instance of the provided type.
|
static <T> T |
fromJSON(String jsonString,
Class<T> returnType)
Unmarshal a JSON string to an instance of the provided type.
|
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.
|
static <T> T |
fromXML(File xmlFile,
Class<T> returnType)
Unmarshal the XML content of a file to an instance of the provided type.
|
static <T> T |
fromXML(InputStream xmlInputStream,
Class<T> returnType)
Unmarshal the XML content of a stream to an instance of the provided type.
|
static <T> T |
fromXML(Reader xmlReader,
Class<T> returnType)
Unmarshal the XML content of a reader to an instance of the provided type.
|
static <T> T |
fromXML(String xmlString,
Class<T> returnType)
Unmarshal an XML string to an instance of the provided type.
|
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.
|
@Autowired MarshallerMethods(io.toro.martini.xml.XMLObjectConverter xmlObjectConverter)
public static String asJSON(Object o) throws ToroException
Marshal an object into a JSON string.
Example usage:
Person person = new Person( firstname: 'John', lastname: 'Doe' ) String json = person.asJSON()
o
- the object to be marshalledToroException
public static String asXML(Object o) throws ToroException
Marshal an object into a JSON string.
Example usage:
Person person = new Person( firstname: 'John', lastname: 'Doe' ) String json = person.asXML()
o
- the object to be marshalledToroException
public static <T> T fromXML(String xmlString, Class<T> returnType) throws ToroException
Unmarshal an XML string to an instance of the provided type.
Example usage:
String xml = ... Person person = xml.fromXML( Person.class )
xmlString
- the XML string to unmarshalreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromXML(File xmlFile, Class<T> returnType) throws ToroException
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 )
xmlFile
- the file containing the XML string to unmarshalreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromXML(InputStream xmlInputStream, Class<T> returnType) throws ToroException
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 ) }
xmlInputStream
- the stream containing the XML string to unmarshalreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromXML(Reader xmlReader, Class<T> returnType) throws ToroException
Unmarshal the XML content of a reader to an instance of the provided type.
Example usage:
Reader xml = ... Person person = xml.fromXML( Person.class )
xmlReader
- the reader containing the XML string to unmarshalreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromXML(URL xmlURL, Class<T> returnType) throws ToroException
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 )
xmlURL
- the URL pointing to the XML document which will be unmarshalledreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromJSON(String jsonString, Class<T> returnType) throws ToroException
Unmarshal a JSON string to an instance of the provided type.
Example usage:
String json = ... Person person = json.fromJSON( Person.class )
jsonString
- the JSON string to unmarshalreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromJSON(File jsonFile, Class<T> returnType) throws ToroException
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 )
jsonFile
- the file containing the JSON string to unmarshalreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromJSON(InputStream jsonInputStream, Class<T> returnType) throws ToroException
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 ) }
jsonInputStream
- the stream containing the JSON string to unmarshalreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromJSON(Reader jsonReader, Class<T> returnType) throws ToroException
Unmarshal the JSON content of a reader to an instance of the provided type.
Example usage:
Reader json = ... Person person = json.fromJSON( Person.class )
jsonReader
- the reader containing the JSON string to unmarshalreturnType
- the type of object where unmarshalled data shall be put intoToroException
public static <T> T fromJSON(URL jsonURL, Class<T> returnType) throws ToroException
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 )
jsonURL
- the URL pointing to the JSON document which will be unmarshalledreturnType
- the type of object where unmarshalled data shall be put intoToroException
Copyright © 2020. All rights reserved.