I am developing a JSON parsing application and want to use ObjectReader
.
I get my instance of object reader as follows -
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final ObjectReader OBJECT_READER = OBJECT_MAPPER.reader(MyType.class);
however the OBJECT_MAPPER.reader(MyType.class);
is showing as deprecated.
What alternative do I have to obtain an ObjectReader
?
ObjectMapper. reader(Class) was deprecated since Jackson 2.5. Starting with Jackson 2.6, you can use readerFor(Class) instead.
ObjectMapper class can be reused and we can initialize it once as Singleton object. There are so many overloaded versions of readValue() and writeValue() methods to work with byte array, File, input/output stream and Reader/Writer objects.
Yes, that is safe and recommended.
ObjectMapper is the main actor class of Jackson library. ObjectMapper class ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionality for performing conversions.
ObjectMapper.reader(Class)
was deprecated since Jackson 2.5.
Starting with Jackson 2.6, you can use readerFor(Class)
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With