public class JSON extends Object
JsonFactory
's to provide the needed codecs.Modifier and Type | Method and Description |
---|---|
static Set<JsonFactory> |
factories()
List all registered factories (unmodifiable)
|
static <T> JsonFactory |
factory(Class<T> factoryClazz)
Retrieve the JSON factory instance by the given class.
|
static <T> T |
fromJson(String json,
Class<T> pojo)
Convert the given JSON string to the given typed POJO.
|
static <T> List<T> |
fromJsonList(String json,
Class<T> pojo)
Convert the given JSON string to a typed list of POJO's.
|
static void |
registerFactory(JsonFactory factory)
Register the given factory with this utility.
|
static <T> String |
toJson(T pojo)
Convert a POJO to its JSON representation with compact formatting.
|
static <T> String |
toJson(T pojo,
boolean prettyPrint)
Convert a POJO to its JSON representation.
|
static <T> String |
toJsonIterator(Iterator<T> pojosIterator,
Class<T> pojo,
boolean prettyPrint)
Convert a collection of POJO's into its JSON representation.
|
static <T> String |
toJsonList(Collection<T> pojos,
Class<T> pojo)
Convert a collection of POJO's into its JSON representation with compact
formatting.
|
static <T> String |
toJsonList(Collection<T> pojos,
Class<T> pojo,
boolean prettyPrint)
Convert a collection of POJO's into its JSON representation.
|
static void |
unregisterFactory(JsonFactory factory)
Unregister the given factory with this utility.
|
public static void registerFactory(JsonFactory factory)
factory
- JsonFactory to registerpublic static void unregisterFactory(JsonFactory factory)
factory
- JsonFactory to unregisterpublic static <T> T fromJson(String json, Class<T> pojo)
json
- JSON string representing an instance of the given POJO
classpojo
- POJO class of the given JSON stringpublic static <T> List<T> fromJsonList(String json, Class<T> pojo)
json
- JSON string representing a typed list of POJO'spojo
- POJO class of the given JSON stringpublic static <T> String toJson(T pojo, boolean prettyPrint)
pojo
- POJO instance to convertprettyPrint
- human-readable formatted JSON if true, single-line
JSON otherwisepublic static <T> String toJson(T pojo)
pojo
- POJO instance to convertpublic static <T> String toJsonList(Collection<T> pojos, Class<T> pojo, boolean prettyPrint)
pojos
- collection of POJO'spojo
- class of POJOprettyPrint
- human-readable formatted JSON if true, single-line
JSON otherwisepublic static <T> String toJsonIterator(Iterator<T> pojosIterator, Class<T> pojo, boolean prettyPrint)
pojosIterator
- collection of POJO'spojo
- class of POJOprettyPrint
- human-readable formatted JSON if true, single-line
JSON otherwisepublic static <T> String toJsonList(Collection<T> pojos, Class<T> pojo)
pojos
- collection of POJO'spojo
- class of POJOpublic static Set<JsonFactory> factories()
public static <T> JsonFactory factory(Class<T> factoryClazz)
factoryClazz
- class of json factory to retrieveCopyright © 2015. All Rights Reserved.