Errai 3.0.1-SNAPSHOT

org.jboss.errai.marshalling.client
Class Marshalling

java.lang.Object
  extended by org.jboss.errai.marshalling.client.Marshalling
Direct Known Subclasses:
ServerMarshalling

public abstract class Marshalling
extends Object

A collection of static methods for accomplishing common tasks with the Errai marshalling API.

Author:
Mike Brock, Jonathan Fuerth , Christian Sadilek

Constructor Summary
Marshalling()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Marshalling

public Marshalling()
Method Detail

canHandle

public static boolean canHandle(Class<?> type)
Returns true if the given type is marshallable by the Errai Marshalling system, and false otherwise.

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.

Parameters:
type - The type to check for marshallability.
Returns:
True for marshallable types and false for non-marshallable types.

getMarshaller

public static <T> Marshaller<T> getMarshaller(Class<T> type)
Returns a marshaller for the type with the provided fully qualified class name. In case no marshaller can be found for that type a RuntimeException will be thrown.

Parameters:
type - the marshallable type.
Returns:
the marshaller instance, never null.

getMarshaller

public static <T> Marshaller<T> getMarshaller(Class<T> type,
                                              DeferredMarshallerCreationCallback<T> creationCallback)
Returns a marshaller for the type with the provided fully qualified class name. In case no marshaller can be found for that type a RuntimeException will be thrown.

Parameters:
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.
Returns:
the marshaller instance, never null.

toJSON

public static String toJSON(Object obj)
Returns a JSON representation of the given object, recursively including all of its nested attributes.

Parameters:
obj - The object to marshall. Should be of a type for which canHandle(Class) returns true. Null is permitted.
Returns:
The JSON representation of the given object and all nested properties reachable from it.

toJSON

public static void toJSON(Appendable appendTo,
                          Object obj)
                   throws IOException
Appends a JSON representation of the given object to the given Appendable, recursively including all of its nested attributes.

Parameters:
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.
Throws:
IOException

toJSON

public static String toJSON(Map<Object,Object> obj)
Works the same as a call to toJSON(Object), but may perform better.

Parameters:
obj - The map to marshal to JSON.
Returns:
The JSON representation of the map.

toJSON

public static String toJSON(List arr)
Works the same as a call to toJSON(Object), but may perform better.

Parameters:
arr - The list to marshal to JSON.
Returns:
The JSON representation of the list.

fromJSON

public 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.

Parameters:
json - The JSON representation of the object graph to demarshall.
type - The expected type of the root of the object graph.
Returns:
the root of the reconstructed object graph.

fromJSON

public 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.

Parameters:
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.
Returns:
the root of the reconstructed object graph.

fromJSON

public 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.

Parameters:
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.
Returns:
the root of the reconstructed object graph.

fromJSON

public 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.

Parameters:
json - The JSON representation of the object graph to demarshall.
Returns:
the root of the reconstructed object graph.

needsQualification

public static boolean needsQualification(Object o)

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.