Package io.camunda.zeebe.client.api
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 Mapinvalid input: '<'String, Object> variables = new HashMapinvalid input: '<'>(); 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 Summary
Modifier and TypeMethodDescription<T> TDeserializes a JSON string into an equivalent POJO of typeT.fromJsonAsMap(String json) Deserializes a JSON string into a string to object map.fromJsonAsStringMap(String json) Deserializes a JSON string into a string to string map.Serializes an object (POJO, map, list, etc.) into an JSON string.validateJson(String propertyName, InputStream jsonInput) Validates a stream that contains a JSON string.validateJson(String propertyName, String jsonInput) Validates a JSON string.
-
Method Details
-
fromJson
Deserializes a JSON string into an equivalent POJO of typeT.- Type Parameters:
T- the type of the returned object- Parameters:
json- the JSON string to deserializetypeClass- the Java type to deserialize into- Returns:
- the POJO deserialized from the given JSON string
- Throws:
InternalClientException- on serialization/deserialization error
-
fromJsonAsMap
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
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
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
Validates a JSON string. If it is not valid throws aInternalClientException.- Parameters:
propertyName- the property name that contains the JSON stringjsonInput- the JSON string- Returns:
- the same JSON string, that passed in
- Throws:
InternalClientException- on serialization/deserialization error
-
validateJson
Validates a stream that contains a JSON string. If it is not valid throws aInternalClientException- Parameters:
propertyName- a property name that contains the streamjsonInput- the stream that contains the JSON string- Returns:
- the JSON string from the stream
- Throws:
InternalClientException- on serialization/deserialization error
-