Package io.camunda.zeebe.client.api
Interface JsonMapper
-
- All Known Implementing Classes:
ZeebeObjectMapper
public interface JsonMapperThis interface is using to customize the way how objects will be serialized and deserialized in JSON format. The default implementation isZeebeObjectMapper. 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
And after doing this:variables = new HashMap<>(); variables.put("a", "b"); variables.put("c", null); 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:
ZeebeObjectMapper
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> TfromJson(String json, Class<T> typeClass)Deserializes a JSON string into an equivalent POJO of typeT.Map<String,Object>fromJsonAsMap(String json)Deserializes a JSON string into a string to object map.Map<String,String>fromJsonAsStringMap(String json)Deserializes a JSON string into a string to string map.StringtoJson(Object value)Serializes an object (POJO, map, list, etc.) into an JSON string.StringvalidateJson(String propertyName, InputStream jsonInput)Validates a stream that contains a JSON string.StringvalidateJson(String propertyName, String jsonInput)Validates a JSON string.
-
-
-
Method Detail
-
fromJson
<T> T fromJson(String json, Class<T> typeClass)
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
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 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
String validateJson(String propertyName, InputStream jsonInput)
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
-
-