public final class Json extends Object
| Modifier and Type | Field and Description |
|---|---|
static com.fasterxml.jackson.databind.ObjectMapper |
MAPPER |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
binaryDecodeValue(byte[] json,
Class<?> parametrized,
Class<?>... parameterClasses)
Example of use:
|
protected static <T> T |
binaryDecodeValue(byte[] payload,
Class<T> clazz) |
static byte[] |
binaryEncode(Object obj)
Encode a POJO to JSON using the underlying Jackson mapper.
|
static <T,H> byte[] |
binaryMarshal(T data,
Map<String,H> headers)
Marshalls the 'data' value as JSON, producing a byte array
|
static <T,A extends Attributes> |
binaryUmarshaller(Class<T> type)
Unmarshals a byte array into T type
|
static <T> T |
decodeValue(String str,
Class<?> parametrized,
Class<?>... parameterClasses)
Example of use:
|
protected static <T> T |
decodeValue(String str,
Class<T> clazz)
Decode a given JSON string to a POJO of the given class type.
|
static <T> T |
decodeValue(String str,
com.fasterxml.jackson.core.type.TypeReference<T> type)
Decode a given JSON string to a POJO of the given type.
|
static String |
encode(Object obj)
Encode a POJO to JSON using the underlying Jackson mapper.
|
static <T> T |
fromInputStream(InputStream inputStream,
Class<T> clazz) |
static <T,H> DataMarshaller<String,T,H> |
marshaller()
Creates a JSON Data Marshaller that produces a
String |
static <T,A extends Attributes> |
umarshaller(Class<T> type)
Creates a JSON Data Unmarshaller
|
public static String encode(Object obj) throws IllegalStateException
obj - a POJOIllegalStateException - if a property cannot be encoded.public static byte[] binaryEncode(Object obj) throws IllegalStateException
obj - a POJOIllegalStateException - if a property cannot be encoded.public static <T> T fromInputStream(InputStream inputStream, Class<T> clazz)
protected static <T> T decodeValue(String str, Class<T> clazz) throws IllegalStateException
T - the generic type.str - the JSON string.clazz - the class to map to.null when str is an empty string or nullIllegalStateException - when there is a parsing or invalid mapping.protected static <T> T binaryDecodeValue(byte[] payload,
Class<T> clazz)
public static <T> T decodeValue(String str, com.fasterxml.jackson.core.type.TypeReference<T> type) throws IllegalStateException
T - the generic type.str - the JSON string.type - the type to map to.null when str is an empty string or nullIllegalStateException - when there is a parsing or invalid mapping.public static <T> T decodeValue(String str, Class<?> parametrized, Class<?>... parameterClasses)
String someJson = "..."; Class> clazz = Much.class; Json.decodeValue(someJson, CloudEventImpl.class, clazz);
T - the generic type.str - The JSON String to parseparametrized - Actual full typeparameterClasses - Type parameters to applynull when str is an empty string or nullObjectMapper.getTypeFactory(),
TypeFactory.constructParametricType(Class, Class...)public static <T> T binaryDecodeValue(byte[] json,
Class<?> parametrized,
Class<?>... parameterClasses)
String someJson = "..."; Class> clazz = Much.class; Json.decodeValue(someJson, CloudEventImpl.class, clazz);
T - the generic type.json - The JSON byte array to parseparametrized - Actual full typeparameterClasses - Type parameters to applynull when str is an empty string or nullObjectMapper.getTypeFactory(),
TypeFactory.constructParametricType(Class, Class...)public static <T,A extends Attributes> DataUnmarshaller<String,T,A> umarshaller(Class<T> type)
T - The 'data' typeA - The attributes typetype - The type of 'data'DataUnmarshallerpublic static <T,A extends Attributes> DataUnmarshaller<byte[],T,A> binaryUmarshaller(Class<T> type)
T - The 'data' typeA - The attributes typepayload - The byte arrayattribues - public static <T,H> DataMarshaller<String,T,H> marshaller()
StringT - The 'data' typeH - The type of headers valueDataMarshallerpublic static <T,H> byte[] binaryMarshal(T data,
Map<String,H> headers)
T - The 'data' typeH - The type of headers valuedata - The 'data' valueheaders - The headersCopyright © 2019. All rights reserved.