Interface Marshall
- All Known Implementing Classes:
JSONMarshall
public interface Marshall
This interface represents the functionality to convert a JSON representation to/from a
Java representation. The serializer's goal is to preserve as much Java structure as
possible: primitive types, arrays, object clusters containing recursive references and so on.
As a consequence, the generated JSON is rather terse. The serializer is the best choice in a
Java centric application where you want to write some object structures to JSON in a readable form.
If the emphasis is on clean JSON, take a look at the Mapper tool, which does not support all Java constructs
but which emits nice JSON which can easily be parsed in e.g. Javascript.
* The main difference between the serializer and the mapper is that the serializer keeps as much
type information and structure information in the JSON data where the mapper uses the type information
in the provided Java classes to interprete the JSON data.
-
Method Summary
Modifier and TypeMethodDescriptionmarshall
(boolean aValue) Convert a boolean primitive to JSON.marshall
(byte aValue) Convert a byte primitive to JSON.marshall
(char aValue) Convert a char primitive to JSON.marshall
(double aValue) Convert a double primitive to JSON.marshall
(float aValue) Convert a float primitive to JSON.marshall
(int aValue) Convert an int primitive to JSON.marshall
(long aValue) Convert a long primitive to JSON.marshall
(short aValue) Convert a short primitive to JSON.Convert a Java object to JSON.unmarshall
(JSONObject aElement) Convert a JSON representation to the Java primitive or reference.
-
Method Details
-
marshall
Convert a boolean primitive to JSON.- Parameters:
aValue
-- Returns:
- An JSON representation of the boolean primitive.
-
marshall
Convert a byte primitive to JSON.- Parameters:
aValue
-- Returns:
- An JSON representation of the byte primitive.
-
marshall
Convert a short primitive to JSON.- Parameters:
aValue
-- Returns:
- An JSON representation of the short primitive.
-
marshall
Convert a char primitive to JSON.- Parameters:
aValue
-- Returns:
- An JSON representation of the char primitive.
-
marshall
Convert an int primitive to JSON.- Parameters:
aValue
-- Returns:
- An JSON representation of the int primitive.
-
marshall
Convert a long primitive to JSON.- Parameters:
aValue
-- Returns:
- An JSON representation of the long primitive.
-
marshall
Convert a float primitive to JSON.- Parameters:
aValue
-- Returns:
- An JSON representation of the float primitive.
-
marshall
Convert a double primitive to JSON.- Parameters:
aValue
-- Returns:
- An JSON representation of the double primitive.
-
marshall
Convert a Java object to JSON.- Parameters:
aObj
-- Returns:
- The JSON representation of the Java object.
- Throws:
MarshallException
- An error occured while converting the Java object to JSON.
-
unmarshall
Convert a JSON representation to the Java primitive or reference.- Parameters:
aElement
-- Returns:
- The Java representation of the JSON. This value can represent a Java primitive value or it can represent a Java reference.
- Throws:
MarshallException
- An error occured while trying to convert the JSON representation into a Java representation.
-