Interface Json
public interface Json
This service provides a simple API to serialize and de-serialize JSON.
The default implementation provided by the server narrows number types to integers if possible, using doubles for decimal values and longs only in case the integral value does not fit in an int.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classException used to report error that occur during serialization or de-serialization of JSON. -
Method Summary
Modifier and TypeMethodDescriptionfromAttributes(Attributes attributes) Serialize the given Attributes to JSON.Map representation of the given JSON String.Map representation of the given JSON String.List<?>fromJsonArray(String jsonArray) Collection representation of the given JSON String, that must be a JSON array.List<?>fromJsonArray(String jsonArray, boolean includeNulls) Collection representation of the given JSON String, that must be a JSON array.toAttributes(String json) Attributes representation of the given JSON String.Serialize the given object to JSON.Serialize the given object to JSON.Serialize the given Map to JSON object.Serialize the given Map to JSON object.
-
Method Details
-
toJson
Serialize the given Map to JSON object.Null values are excluded. To keep them, use
toJson(Map, boolean).- Parameters:
object- to serialize- Returns:
- JSON representation of the given Map.
- Throws:
Json.JsonException- if any type within the given Map cannot be serialized.
-
toJson
Serialize the given Map to JSON object.- Parameters:
object- to serializeincludeNulls- whether nulls should be included in the JSON result- Returns:
- JSON representation of the given Map.
- Throws:
Json.JsonException- if any type within the given Map cannot be serialized.
-
toJson
Serialize the given object to JSON.Null values are excluded. To keep them, use
toJson(Object, boolean).- Parameters:
object- to serialize- Returns:
- JSON representation of the given object.
- Throws:
Json.JsonException- if any type within the given object cannot be serialized.- Since:
- 2.2.0
-
toJson
Serialize the given object to JSON.- Parameters:
object- to serializeincludeNulls- whether nulls should be included in the JSON result- Returns:
- JSON representation of the given object.
- Throws:
Json.JsonException- if any type within the given object cannot be serialized.- Since:
- 2.2.0
-
fromJson
Map representation of the given JSON String.Nulls are excluded. To keep nulls in the result, use
fromJson(String, boolean).- Parameters:
json- to de-serialize- Returns:
- Map representation of the given JSON String.
- Throws:
Json.JsonException- if the String cannot be de-serialized due to syntax errors or any other reason.
-
fromJson
Map representation of the given JSON String.- Parameters:
json- to de-serializeincludeNulls- whether nulls should be included in the Map result- Returns:
- Map representation of the given JSON String.
- Throws:
Json.JsonException- if the String cannot be de-serialized due to syntax errors or any other reason.
-
fromJsonArray
Collection representation of the given JSON String, that must be a JSON array.Nulls are excluded. To keep nulls in the result, use
fromJsonArray(String, boolean).- Parameters:
jsonArray- to de-serialize- Returns:
- Collection representation of the given JSON String.
- Throws:
Json.JsonException- if the String cannot be de-serialized due to syntax errors or any other reason.- Since:
- 2.2.0
-
fromJsonArray
Collection representation of the given JSON String, that must be a JSON array.- Parameters:
jsonArray- to de-serializeincludeNulls- whether nulls should be included in the Collection result- Returns:
- Collection representation of the given JSON String.
- Throws:
Json.JsonException- if the String cannot be de-serialized due to syntax errors or any other reason.- Since:
- 2.2.0
-
toAttributes
Attributes representation of the given JSON String.- Parameters:
json- to de-serialize- Returns:
- Attributes representation of the given JSON String.
- Throws:
Json.JsonException- if the String cannot be de-serialized due to syntax errors or any other reason.
-
fromAttributes
Serialize the given Attributes to JSON.- Parameters:
attributes- to serialize- Returns:
- JSON representation of the given Attributes.
- Throws:
Json.JsonException- if any exception is encountered during serialization
-