Package io.vertx.core.json.jackson
Class JacksonCodec
- java.lang.Object
-
- io.vertx.core.json.jackson.JacksonCodec
-
- All Implemented Interfaces:
JsonCodec
- Direct Known Subclasses:
DatabindCodec
public class JacksonCodec extends Object implements JsonCodec
- Author:
- Julien Viet
-
-
Constructor Summary
Constructors Constructor Description JacksonCodec()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JsonParser
createParser(Buffer buf)
static JsonParser
createParser(String str)
static <T> T
decodeValue(Buffer buf, TypeReference<T> type)
Decode a given JSON buffer to a POJO of the given class type.static <T> T
decodeValue(String str, TypeReference<T> type)
Decode a given JSON string to a POJO of the given type.static void
encodeJson(Object json, JsonGenerator generator)
Object
fromBuffer(Buffer buf)
<T> T
fromBuffer(Buffer buf, TypeReference<T> typeRef)
<T> T
fromBuffer(Buffer json, Class<T> clazz)
LikeJsonCodec.fromString(String, Class)
but with a jsonBuffer
static <T> T
fromParser(JsonParser parser, Class<T> type)
Object
fromString(String str)
<T> T
fromString(String str, TypeReference<T> typeRef)
<T> T
fromString(String json, Class<T> clazz)
Decode the providejson
string to an object extendingclazz
.<T> T
fromValue(Object json, TypeReference<T> type)
<T> T
fromValue(Object json, Class<T> toValueType)
LikeJsonCodec.fromString(String, Class)
but with a jsonObject
Buffer
toBuffer(Object object, boolean pretty)
LikeJsonCodec.toString(Object, boolean)
but with a jsonBuffer
String
toString(Object object, boolean pretty)
Encode the specifiedobject
to a string.
-
-
-
Method Detail
-
fromString
public <T> T fromString(String json, Class<T> clazz) throws DecodeException
Description copied from interface:JsonCodec
Decode the providejson
string to an object extendingclazz
.- Specified by:
fromString
in interfaceJsonCodec
- Parameters:
json
- the json stringclazz
- the required object's class- Returns:
- the instance
- Throws:
DecodeException
- anything preventing the decoding
-
fromString
public <T> T fromString(String str, TypeReference<T> typeRef) throws DecodeException
- Throws:
DecodeException
-
fromBuffer
public <T> T fromBuffer(Buffer json, Class<T> clazz) throws DecodeException
Description copied from interface:JsonCodec
LikeJsonCodec.fromString(String, Class)
but with a jsonBuffer
- Specified by:
fromBuffer
in interfaceJsonCodec
- Throws:
DecodeException
-
fromBuffer
public <T> T fromBuffer(Buffer buf, TypeReference<T> typeRef) throws DecodeException
- Throws:
DecodeException
-
fromValue
public <T> T fromValue(Object json, Class<T> toValueType)
Description copied from interface:JsonCodec
LikeJsonCodec.fromString(String, Class)
but with a jsonObject
-
fromValue
public <T> T fromValue(Object json, TypeReference<T> type)
-
toString
public String toString(Object object, boolean pretty) throws EncodeException
Description copied from interface:JsonCodec
Encode the specifiedobject
to a string.- Specified by:
toString
in interfaceJsonCodec
- Parameters:
object
- the object to encodepretty
-true
to format the string prettily- Returns:
- the json encoded string
- Throws:
EncodeException
-
toBuffer
public Buffer toBuffer(Object object, boolean pretty) throws EncodeException
Description copied from interface:JsonCodec
LikeJsonCodec.toString(Object, boolean)
but with a jsonBuffer
- Specified by:
toBuffer
in interfaceJsonCodec
- Throws:
EncodeException
-
createParser
public static JsonParser createParser(String str)
-
createParser
public static JsonParser createParser(Buffer buf)
-
fromString
public Object fromString(String str) throws DecodeException
- Throws:
DecodeException
-
fromBuffer
public Object fromBuffer(Buffer buf) throws DecodeException
- Throws:
DecodeException
-
fromParser
public static <T> T fromParser(JsonParser parser, Class<T> type) throws DecodeException
- Throws:
DecodeException
-
encodeJson
public static void encodeJson(Object json, JsonGenerator generator) throws EncodeException
- Throws:
EncodeException
-
decodeValue
public static <T> T decodeValue(String str, TypeReference<T> type) throws DecodeException
Decode a given JSON string to a POJO of the given type.- Type Parameters:
T
- the generic type.- Parameters:
str
- the JSON string.type
- the type to map to.- Returns:
- an instance of T
- Throws:
DecodeException
- when there is a parsing or invalid mapping.
-
decodeValue
public static <T> T decodeValue(Buffer buf, TypeReference<T> type) throws DecodeException
Decode a given JSON buffer to a POJO of the given class type.- Type Parameters:
T
- the generic type.- Parameters:
buf
- the JSON buffer.type
- the type to map to.- Returns:
- an instance of T
- Throws:
DecodeException
- when there is a parsing or invalid mapping.
-
-