Interface JsonCodec
- All Known Implementing Classes:
DatabindCodec, JacksonCodec
public interface JsonCodec
- Author:
- Julien Viet
-
Method Summary
Modifier and TypeMethodDescription<T> TfromBuffer(Buffer json, Class<T> clazz) LikefromString(String, Class)but with a jsonBufferdefault ObjectfromReader(Reader reader) Decode JSON from the givenReader.default <T> TfromReader(Reader reader, Class<T> clazz) Decode JSON from the givenReaderto an object of the specified type.default ObjectDecode JSON from the givenInputStream.default <T> TfromStream(InputStream in, Class<T> clazz) Decode JSON from the givenInputStreamto an object of the specified type.<T> TfromString(String json, Class<T> clazz) Decode the providejsonstring to an object extendingclazz.<T> TLikefromString(String, Class)but with a jsonObjectdefault BufferLiketoString(Object)but with a jsonBufferLiketoString(Object, boolean)but with a jsonBufferdefault voidtoStream(Object object, OutputStream out) Encode the specified object as JSON to the givenOutputStream.default StringEncode the specifiedobjectto a string.Encode the specifiedobjectto a string.default voidEncode the specified object as JSON to the givenWriter.
-
Method Details
-
fromString
Decode the providejsonstring to an object extendingclazz.- Parameters:
json- the json stringclazz- the required object's class- Returns:
- the instance
- Throws:
DecodeException- anything preventing the decoding
-
fromBuffer
LikefromString(String, Class)but with a jsonBuffer- Throws:
DecodeException
-
fromValue
LikefromString(String, Class)but with a jsonObject -
toString
Encode the specifiedobjectto a string.- Throws:
EncodeException
-
toString
Encode the specifiedobjectto a string.- Parameters:
object- the object to encodepretty-trueto format the string prettily- Returns:
- the json encoded string
- Throws:
DecodeException- anything preventing the encodingEncodeException
-
toBuffer
LiketoString(Object, boolean)but with a jsonBuffer- Throws:
EncodeException
-
toBuffer
LiketoString(Object)but with a jsonBuffer- Throws:
EncodeException
-
fromStream
Decode 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.
- 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
-
fromStream
Decode JSON from the givenInputStream.The input is expected to be UTF-8 encoded.
The codec does not close or flush the stream; the caller retains ownership.
- Parameters:
in- the input stream containing UTF-8 encoded JSON- Returns:
- a JSON element which can be a
JsonArray,JsonObject,String, etc. - Throws:
DecodeException- anything preventing the decoding
-
toStream
Encode 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.
- Parameters:
object- the object to encodeout- the output stream to write to- Throws:
EncodeException- anything preventing the encoding
-
fromReader
Decode JSON from the givenReaderto an object of the specified type.The codec does not close or flush the reader; the caller retains ownership.
- Parameters:
reader- the reader containing JSON textclazz- the required object's class- Returns:
- the decoded instance
- Throws:
DecodeException- anything preventing the decoding
-
fromReader
Decode JSON from the givenReader.The codec does not close or flush the reader; the caller retains ownership.
- Parameters:
reader- the reader containing JSON text- Returns:
- a JSON element which can be a
JsonArray,JsonObject,String, etc. - Throws:
DecodeException- anything preventing the decoding
-
toWriter
Encode the specified object as JSON to the givenWriter.The codec does not close or flush the writer; the caller retains ownership.
- Parameters:
object- the object to encodewriter- the writer to write to- Throws:
EncodeException- anything preventing the encoding
-