Class Json
java.lang.Object
io.vertx.core.json.Json
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectdecodeValue(Buffer buf) Decode a given JSON buffer.static <T> TdecodeValue(Buffer buf, Class<T> clazz) Decode a given JSON buffer to a POJO of the given class type.static ObjectDecode a given JSON input stream.static <T> TdecodeValue(InputStream in, Class<T> clazz) Decode a given JSON input stream to a POJO of the given class type.static ObjectdecodeValue(Reader reader) Decode a given JSON reader.static <T> TdecodeValue(Reader reader, Class<T> clazz) Decode a given JSON reader to a POJO of the given class type.static ObjectdecodeValue(String str) Decode a given JSON string.static <T> TdecodeValue(String str, Class<T> clazz) Decode a given JSON string to a POJO of the given class type.static StringEncode a POJO to JSON using the underlying Jackson mapper.static StringencodePrettily(Object obj) Encode a POJO to JSON with pretty indentation, using the underlying Jackson mapper.static voidencodeTo(Object obj, OutputStream out) Encode a POJO to JSON and write it to the givenOutputStream.static voidEncode a POJO to JSON and write it to the givenWriter.static BufferencodeToBuffer(Object obj) Encode a POJO to JSON using the underlying Jackson mapper.static JsonFactoryload()Load the factory with theServiceLoader, when no factory is found then a factory using Jackson will be returned.
-
Field Details
-
CODEC
This will load the default codec.
-
-
Constructor Details
-
Json
public Json()
-
-
Method Details
-
load
Load the factory with theServiceLoader, when no factory is found then a factory using Jackson will be returned.
Whenjackson-databindis available then a codec using it will be used otherwise the codec will only usejackson-coreand provide best effort mapping. -
encode
Encode a POJO to JSON using the underlying Jackson mapper.- Parameters:
obj- a POJO- Returns:
- a String containing the JSON representation of the given POJO.
- Throws:
EncodeException- if a property cannot be encoded.
-
encodeToBuffer
Encode a POJO to JSON using the underlying Jackson mapper.- Parameters:
obj- a POJO- Returns:
- a Buffer containing the JSON representation of the given POJO.
- Throws:
EncodeException- if a property cannot be encoded.
-
encodePrettily
Encode a POJO to JSON with pretty indentation, using the underlying Jackson mapper.- Parameters:
obj- a POJO- Returns:
- a String containing the JSON representation of the given POJO.
- Throws:
EncodeException- if a property cannot be encoded.
-
decodeValue
Decode a given JSON string to a POJO of the given class type.- Type Parameters:
T- the generic type.- Parameters:
str- the JSON string.clazz- the class to map to.- Returns:
- an instance of T
- Throws:
DecodeException- when there is a parsing or invalid mapping.
-
decodeValue
Decode a given JSON string.- Parameters:
str- the JSON string.- Returns:
- a JSON element which can be a
JsonArray,JsonObject,String, ...etc if the content is an array, object, string, ...etc - Throws:
DecodeException- when there is a parsing or invalid mapping.
-
decodeValue
Decode a given JSON buffer.- Parameters:
buf- the JSON buffer.- Returns:
- a JSON element which can be a
JsonArray,JsonObject,String, ...etc if the buffer contains an array, object, string, ...etc - Throws:
DecodeException- when there is a parsing or invalid mapping.
-
decodeValue
Decode a given JSON buffer to a POJO of the given class type.- Type Parameters:
T- the generic type.- Parameters:
buf- the JSON buffer.clazz- the class to map to.- Returns:
- an instance of T
- Throws:
DecodeException- when there is a parsing or invalid mapping.
-
decodeValue
Decode a given JSON input stream to a POJO of the given class type.The input is expected to be UTF-8 encoded. The codec does not close or flush the stream.
- Type Parameters:
T- the generic type.- Parameters:
in- the JSON input stream.clazz- the class to map to.- Returns:
- an instance of T
- Throws:
DecodeException- when there is a parsing or invalid mapping.
-
decodeValue
Decode a given JSON input stream.The input is expected to be UTF-8 encoded. The codec does not close or flush the stream.
- Parameters:
in- the JSON input stream.- Returns:
- a JSON element which can be a
JsonArray,JsonObject,String, etc. - Throws:
DecodeException- when there is a parsing or invalid mapping.
-
encodeTo
Encode a POJO to JSON and write it to the givenOutputStream.The output is UTF-8 encoded. The codec does not close or flush the stream.
- Parameters:
obj- a POJOout- the output stream to write to- Throws:
EncodeException- if a property cannot be encoded.
-
decodeValue
Decode a given JSON reader to a POJO of the given class type.The codec does not close or flush the reader.
- Type Parameters:
T- the generic type.- Parameters:
reader- the JSON reader.clazz- the class to map to.- Returns:
- an instance of T
- Throws:
DecodeException- when there is a parsing or invalid mapping.
-
decodeValue
Decode a given JSON reader.The codec does not close or flush the reader.
- Parameters:
reader- the JSON reader.- Returns:
- a JSON element which can be a
JsonArray,JsonObject,String, etc. - Throws:
DecodeException- when there is a parsing or invalid mapping.
-
encodeTo
Encode a POJO to JSON and write it to the givenWriter.The codec does not close or flush the writer.
- Parameters:
obj- a POJOwriter- the writer to write to- Throws:
EncodeException- if a property cannot be encoded.
-