public class JSONConverter<T> extends Object implements Converter<T>
RiakKey or you must construct the converter with a key to use. RiakObject's value *must* be a JSON string.
At present user meta data and RiakLinks are not converted. This means
they are essentially lost in translation.
| Constructor and Description |
|---|
JSONConverter(Class<T> clazz,
String bucket)
Create a JSONConverter for creating instances of
clazz from
JSON and instances of IRiakObject with a JSON payload from
instances of clazz |
JSONConverter(Class<T> clazz,
String bucket,
String defaultKey)
Create a JSONConverter for creating instances of
clazz from
JSON and instances of IRiakObject with a JSON payload from
instances of clazz |
| Modifier and Type | Method and Description |
|---|---|
IRiakObject |
fromDomain(T domainObject,
VClock vclock)
Converts
domainObject to a JSON string and sets that as the
payload of a IRiakObject. |
static com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper()
Returns the
ObjectMapper being used. |
static void |
registerJacksonModule(com.fasterxml.jackson.databind.Module jacksonModule)
Convenient method to register a Jackson module into the singleton Object mapper used by domain objects.
|
T |
toDomain(IRiakObject riakObject)
Converts the
value of riakObject to an instance
of T. |
public JSONConverter(Class<T> clazz, String bucket)
clazz from
JSON and instances of IRiakObject with a JSON payload from
instances of clazzclazz - the type to convert to/frombucket - the bucketpublic JSONConverter(Class<T> clazz, String bucket, String defaultKey)
clazz from
JSON and instances of IRiakObject with a JSON payload from
instances of clazzclazz - the type to convert to/frombucket - the bucketdefaultKey - for cases where clazz does not have a
RiakKey annotated field, pass the key to use in this
conversion.public IRiakObject fromDomain(T domainObject, VClock vclock) throws ConversionException
domainObject to a JSON string and sets that as the
payload of a IRiakObject. Also set the content-type
to application/json;charset=UTF-8fromDomain in interface Converter<T>domainObject - to be convertedvclock - the vector clock from RiakConversionExceptionpublic T toDomain(IRiakObject riakObject) throws ConversionException
value of riakObject to an instance
of T.toDomain in interface Converter<T>riakObject - the IRiakObject to convert to instance of
T. NOTE: riakObject.getValue() must be a
JSON string. The charset from
riakObject.getContentType() is used.ConversionExceptionpublic static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
ObjectMapper being used.
This is a convenience method to allow changing its behavior.public static void registerJacksonModule(com.fasterxml.jackson.databind.Module jacksonModule)
jacksonModule - Module to register.Copyright © 2014. All Rights Reserved.