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 Classes
    Modifier and Type
    Interface
    Description
    static class 
    Exception used to report error that occur during serialization or de-serialization of JSON.
  • Method Summary

    Modifier and Type
    Method
    Description
    Serialize the given Attributes to JSON.
    Map representation of the given JSON String.
    fromJson(String json, boolean includeNulls)
    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.
    Attributes representation of the given JSON String.
    toJson(Object object)
    Serialize the given object to JSON.
    toJson(Object object, boolean includeNulls)
    Serialize the given object to JSON.
    toJson(Map<?,?> object)
    Serialize the given Map to JSON object.
    toJson(Map<?,?> object, boolean includeNulls)
    Serialize the given Map to JSON object.
  • Method Details

    • toJson

      String toJson(Map<?,?> object)
      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

      String toJson(Map<?,?> object, boolean includeNulls)
      Serialize the given Map to JSON object.
      Parameters:
      object - to serialize
      includeNulls - 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

      String toJson(Object object)
      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

      String toJson(Object object, boolean includeNulls)
      Serialize the given object to JSON.
      Parameters:
      object - to serialize
      includeNulls - 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<String,Object> fromJson(String json)
      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<String,Object> fromJson(String json, boolean includeNulls)
      Map representation of the given JSON String.
      Parameters:
      json - to de-serialize
      includeNulls - 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

      List<?> fromJsonArray(String jsonArray)
      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

      List<?> fromJsonArray(String jsonArray, boolean includeNulls)
      Collection representation of the given JSON String, that must be a JSON array.
      Parameters:
      jsonArray - to de-serialize
      includeNulls - 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 toAttributes(String json)
      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

      String fromAttributes(Attributes attributes)
      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