Class JacksonCodec
java.lang.Object
io.vertx.core.json.jackson.JacksonCodec
- All Implemented Interfaces:
JsonCodec
- Direct Known Subclasses:
DatabindCodec
- Author:
- Julien Viet
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonParsercreateParser(Buffer buf) static JsonParsercreateParser(String str) static voidencodeJson(Object json, JsonGenerator generator) fromBuffer(Buffer buf) <T> TfromBuffer(Buffer json, Class<T> clazz) LikeJsonCodec.fromString(String, Class)but with a jsonBufferstatic <T> TfromParser(JsonParser parser, Class<T> type) <T> TfromReader(Reader reader, Class<T> clazz) Decode JSON from the givenReaderto an object of the specified type.<T> TfromStream(InputStream in, Class<T> clazz) Decode JSON from the givenInputStreamto an object of the specified type.fromString(String str) <T> TfromString(String json, Class<T> clazz) Decode the providejsonstring to an object extendingclazz.<T> TLikeJsonCodec.fromString(String, Class)but with a jsonObjectparseArray(JsonParser parser) Parse a JSON array given theparser, the parser current token must beJsonTokenId.ID_START_ARRAYparseObject(JsonParser parser) Parse a JSON object given theparser, the parser current token must beJsonTokenId.ID_START_OBJECTstatic ObjectparseValue(JsonParser parser) Parse a JSON value given theparser, consuming the current parser token and possibly more when parsing an object or an array.LikeJsonCodec.toString(Object, boolean)but with a jsonBuffervoidtoStream(Object object, OutputStream out) Encode the specified object as JSON to the givenOutputStream.Encode the specifiedobjectto a string.voidEncode the specified object as JSON to the givenWriter.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface JsonCodec
fromReader, fromStream, toBuffer, toString
-
Constructor Details
-
JacksonCodec
public JacksonCodec()
-
-
Method Details
-
fromString
Description copied from interface:JsonCodecDecode the providejsonstring to an object extendingclazz.- Specified by:
fromStringin interfaceJsonCodec- Parameters:
json- the json stringclazz- the required object's class- Returns:
- the instance
- Throws:
DecodeException- anything preventing the decoding
-
fromBuffer
Description copied from interface:JsonCodecLikeJsonCodec.fromString(String, Class)but with a jsonBuffer- Specified by:
fromBufferin interfaceJsonCodec- Throws:
DecodeException
-
fromStream
Description copied from interface:JsonCodecDecode JSON from the givenInputStreamto an object of the specified type.The input is expected to be UTF-8 encoded.
The codec does not close or flush the stream; the caller retains ownership.
- Specified by:
fromStreamin interfaceJsonCodec- Parameters:
in- the input stream containing UTF-8 encoded JSONclazz- the required object's class- Returns:
- the decoded instance
- Throws:
DecodeException- anything preventing the decoding
-
fromValue
-
toString
Description copied from interface:JsonCodecEncode the specifiedobjectto a string.- Specified by:
toStringin interfaceJsonCodec- Parameters:
object- the object to encodepretty-trueto format the string prettily- Returns:
- the json encoded string
- Throws:
EncodeException
-
toBuffer
Description copied from interface:JsonCodecLikeJsonCodec.toString(Object, boolean)but with a jsonBuffer- Specified by:
toBufferin interfaceJsonCodec- Throws:
EncodeException
-
toStream
Description copied from interface:JsonCodecEncode the specified object as JSON to the givenOutputStream.The output is UTF-8 encoded.
The codec does not close or flush the stream; the caller retains ownership.
- Specified by:
toStreamin interfaceJsonCodec- Parameters:
object- the object to encodeout- the output stream to write to- Throws:
EncodeException- anything preventing the encoding
-
fromReader
Description copied from interface:JsonCodecDecode JSON from the givenReaderto an object of the specified type.The codec does not close or flush the reader; the caller retains ownership.
- Specified by:
fromReaderin interfaceJsonCodec- Parameters:
reader- the reader containing JSON textclazz- the required object's class- Returns:
- the decoded instance
- Throws:
DecodeException- anything preventing the decoding
-
toWriter
Description copied from interface:JsonCodecEncode the specified object as JSON to the givenWriter.The codec does not close or flush the writer; the caller retains ownership.
- Specified by:
toWriterin interfaceJsonCodec- Parameters:
object- the object to encodewriter- the writer to write to- Throws:
EncodeException- anything preventing the encoding
-
createParser
-
createParser
-
fromString
- Throws:
DecodeException
-
fromBuffer
- Throws:
DecodeException
-
fromParser
- Throws:
DecodeException
-
parseValue
Parse a JSON value given theparser, consuming the current parser token and possibly more when parsing an object or an array.- Parameters:
parser- the parser- Returns:
- the parsed value as an object
- Throws:
IOExceptionDecodeException
-
parseObject
Parse a JSON object given theparser, the parser current token must beJsonTokenId.ID_START_OBJECT- Parameters:
parser- the parser- Returns:
- the parsed object
- Throws:
IOException
-
parseArray
Parse a JSON array given theparser, the parser current token must beJsonTokenId.ID_START_ARRAY- Parameters:
parser- the parser- Returns:
- the parsed array
- Throws:
IOException
-
encodeJson
- Throws:
EncodeException
-