Interface JsonMapper

All Known Implementing Classes:
ZeebeObjectMapper

public interface JsonMapper
This interface is using to customize the way how objects will be serialized and deserialized in JSON format. The default implementation is ZeebeObjectMapper. This interface could be implemented to customize the way how variables in the commands serialized/deserialized. For example: there is such map with variables:
   final Map<String, Object> variables = new HashMap<>();
   variables.put("a", "b");
   variables.put("c", null);
 
And after doing this:
   public class MyJsonMapper implements JsonMapper {

     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().setSerializationInclusion(Include.NON_NULL);

     public String toJson(final Object value) {
       return OBJECT_MAPPER.writeValueAsString(value);
     }
     ...
   }
   ...
   ZeebeClient.newClientBuilder().withJsonMapper(new MyJsonMapper());
 
Null values won't pass in the JSON with variables: { "a": "b" }
See Also:
  • Method Details

    • fromJson

      <T> T fromJson(String json, Class<T> typeClass)
      Deserializes a JSON string into an equivalent POJO of type T.
      Type Parameters:
      T - the type of the returned object
      Parameters:
      json - the JSON string to deserialize
      typeClass - the Java type to deserialize into
      Returns:
      the POJO deserialized from the given JSON string
      Throws:
      InternalClientException - on serialization/deserialization error
    • fromJsonAsMap

      Map<String,Object> fromJsonAsMap(String json)
      Deserializes a JSON string into a string to object map.
      Parameters:
      json - the JSON string to deserialize
      Returns:
      the map deserialized from the given JSON string
      Throws:
      InternalClientException - on serialization/deserialization error
    • fromJsonAsStringMap

      Map<String,String> fromJsonAsStringMap(String json)
      Deserializes a JSON string into a string to string map.
      Parameters:
      json - the JSON string to deserialize
      Returns:
      the map deserialized from the given JSON string
      Throws:
      InternalClientException - on serialization/deserialization error
    • toJson

      String toJson(Object value)
      Serializes an object (POJO, map, list, etc.) into an JSON string.
      Parameters:
      value - the object to serialize
      Returns:
      a JSON string serialized from the given object
      Throws:
      InternalClientException - on serialization/deserialization error
    • validateJson

      String validateJson(String propertyName, String jsonInput)
      Validates a JSON string. If it is not valid throws a InternalClientException.
      Parameters:
      propertyName - the property name that contains the JSON string
      jsonInput - the JSON string
      Returns:
      the same JSON string, that passed in
      Throws:
      InternalClientException - on serialization/deserialization error
    • validateJson

      String validateJson(String propertyName, InputStream jsonInput)
      Validates a stream that contains a JSON string. If it is not valid throws a InternalClientException
      Parameters:
      propertyName - a property name that contains the stream
      jsonInput - the stream that contains the JSON string
      Returns:
      the JSON string from the stream
      Throws:
      InternalClientException - on serialization/deserialization error