public abstract class Marshalling extends Object
Constructor and Description |
---|
Marshalling() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canHandle(Class<?> type)
Returns true if the given type is marshallable by the Errai Marshalling system, and false
otherwise.
|
static Object |
fromJSON(String json)
Converts the given JSON message to a Java object, recursively decoding nested attributes
contained in that message, which must contain type information for the root object.
|
static <T> T |
fromJSON(String json,
Class<T> type)
Converts the given JSON message to a Java object, recursively decoding nested attributes
contained in that message.
|
static <T> T |
fromJSON(String json,
Class<T> type,
Class<?> assumedElementType)
Converts the given JSON message (which is likely a collection) to a Java object, recursively
decoding nested attributes contained in that message.
|
static <T> T |
fromJSON(String json,
Class<T> type,
Class<?> assumedMapKeyType,
Class<?> assumedMapValueType)
Converts the given JSON message to a Java map object, recursively decoding nested attributes
contained in that message.
|
static <T> Marshaller<T> |
getMarshaller(Class<T> type)
Returns a marshaller for the type with the provided fully qualified class name.
|
static <T> Marshaller<T> |
getMarshaller(Class<T> type,
DeferredMarshallerCreationCallback<T> creationCallback)
Returns a marshaller for the type with the provided fully qualified class name.
|
static boolean |
needsQualification(Object o) |
static void |
toJSON(Appendable appendTo,
Object obj)
Appends a JSON representation of the given object to the given Appendable, recursively
including all of its nested attributes.
|
static String |
toJSON(List arr)
Works the same as a call to
toJSON(Object) , but may perform better. |
static String |
toJSON(Map<Object,Object> obj)
Works the same as a call to
toJSON(Object) , but may perform better. |
static String |
toJSON(Object obj)
Returns a JSON representation of the given object, recursively including all of its nested
attributes.
|
public static boolean canHandle(Class<?> type)
Marshallable types include all native Java types, most built-in Java API types, types annotated
with @Portable
, types configured for marshalling via ErraiApp.properties
, and
arrays, Collections, and Maps of marshallable types.
type
- The type to check for marshallability.public static <T> Marshaller<T> getMarshaller(Class<T> type)
type
- the marshallable type.public static <T> Marshaller<T> getMarshaller(Class<T> type, DeferredMarshallerCreationCallback<T> creationCallback)
type
- the marshallable type.creationCallback
- A callback that will be used to create a marshaller for the provided type in case it
hasn't already been created.public static String toJSON(Object obj)
obj
- The object to marshall. Should be of a type for which canHandle(Class)
returns true. Null is permitted.public static void toJSON(Appendable appendTo, Object obj) throws IOException
appendTo
- the Appendable to write the JSON representation to.obj
- The object to marshall. Should be of a type for which canHandle(Class)
returns true. Null is permitted.IOException
public static String toJSON(Map<Object,Object> obj)
toJSON(Object)
, but may perform better.obj
- The map to marshal to JSON.public static String toJSON(List arr)
toJSON(Object)
, but may perform better.arr
- The list to marshal to JSON.public static <T> T fromJSON(String json, Class<T> type)
json
- The JSON representation of the object graph to demarshall.type
- The expected type of the root of the object graph.public static <T> T fromJSON(String json, Class<T> type, Class<?> assumedElementType)
json
- The JSON representation of the object graph to demarshall.type
- The expected type of the root of the object graph.assumedElementType
- the type of elements assumed to be in the root collection. A null value means that
either the root object is not a collection, or its element type is provided in the
JSON message.public static <T> T fromJSON(String json, Class<T> type, Class<?> assumedMapKeyType, Class<?> assumedMapValueType)
json
- The JSON representation of the object graph to demarshall.type
- The expected type of the root of the object graph.assumedMapKeyType
- the key type used in the map.assumedMapValueType
- the value type used in the map.public static Object fromJSON(String json)
json
- The JSON representation of the object graph to demarshall.public static boolean needsQualification(Object o)
Copyright © 2013-2015 JBoss, a division of Red Hat. All Rights Reserved.