Interface Json.JsonCodec
- All Known Implementing Classes:
Jackson3JsonCodec, Jackson3ProviderJsonCodec, Jackson3StateJsonCodec
- Enclosing class:
Json
public static interface Json.JsonCodec
The abstract JSON codec interface.
A new implementation should report every failure as a JsonException: a
JsonReadException when reading, a JsonWriteException when writing, keeping
its JSON library's own exception as the cause. That is what
lets one implementation stand in for another without callers noticing which library is
underneath.
The Jackson 2 implementations shipped here do not do that yet - they wrap the library's
exception in a plain RuntimeException, as they always have, and will move in the next
major version. So a caller that must work against any implementation catches
RuntimeException.
-
Method Summary
Modifier and TypeMethodDescription<T> TConvert the given JSON string to an object of the given class.<T> TConvert the given JSON string to an object of the given type.Convert the given object to JSON.
-
Method Details
-
toJson
Convert the given object to JSON.- Parameters:
o- the object to convert.- Returns:
- the JSON string.
- Throws:
JsonWriteException- if the object has no JSON representation, from an implementation that reports the typed exceptions; otherwise aRuntimeException.
-
fromJson
Convert the given JSON string to an object of the given class.- Type Parameters:
T- the type of the object.- Parameters:
json- the JSON string.type- the class of the object.- Returns:
- the object.
- Throws:
JsonReadException- if the JSON is malformed or does not describe the given type, from an implementation that reports the typed exceptions; otherwise aRuntimeException.
-
fromJson
Convert the given JSON string to an object of the given type.- Type Parameters:
T- the type of the object.- Parameters:
json- the JSON string.type- the type of the object.- Returns:
- the object.
- Throws:
JsonReadException- if the JSON is malformed or does not describe the given type, from an implementation that reports the typed exceptions; otherwise aRuntimeException.
-