Class JacksonJsonObjectReader<T>
java.lang.Object
org.springframework.batch.item.json.JacksonJsonObjectReader<T>
- Type Parameters:
T
- type of the target object
- All Implemented Interfaces:
JsonObjectReader<T>
Implementation of
JsonObjectReader
based on
Jackson.- Since:
- 4.1
- Author:
- Mahmoud Ben Hassine, Jimmy Praet
-
Constructor Summary
ConstructorDescriptionJacksonJsonObjectReader
(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<? extends T> itemType) JacksonJsonObjectReader
(Class<? extends T> itemType) Create a newJacksonJsonObjectReader
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the input resource.void
jumpToItem
(int itemIndex) Move to the given item index.void
open
(org.springframework.core.io.Resource resource) Open the Json resource for reading.read()
Read the next object in the Json resource if any.void
setMapper
(com.fasterxml.jackson.databind.ObjectMapper mapper) Set the object mapper to use to map Json objects to domain objects.
-
Constructor Details
-
JacksonJsonObjectReader
Create a newJacksonJsonObjectReader
instance.- Parameters:
itemType
- the target item type
-
JacksonJsonObjectReader
-
-
Method Details
-
setMapper
public void setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) Set the object mapper to use to map Json objects to domain objects.- Parameters:
mapper
- the object mapper to use- See Also:
-
open
Description copied from interface:JsonObjectReader
Open the Json resource for reading.- Specified by:
open
in interfaceJsonObjectReader<T>
- Parameters:
resource
- the input resource- Throws:
Exception
- if unable to open the resource
-
read
Description copied from interface:JsonObjectReader
Read the next object in the Json resource if any.- Specified by:
read
in interfaceJsonObjectReader<T>
- Returns:
- the next object or
null
if the resource is exhausted - Throws:
Exception
- if unable to read the next object
-
close
Description copied from interface:JsonObjectReader
Close the input resource.- Specified by:
close
in interfaceJsonObjectReader<T>
- Throws:
Exception
- if unable to close the input resource
-
jumpToItem
Description copied from interface:JsonObjectReader
Move to the given item index. Implementations should override this method if there is a more efficient way of moving to given index than re-reading the input usingJsonObjectReader.read()
.- Specified by:
jumpToItem
in interfaceJsonObjectReader<T>
- Parameters:
itemIndex
- index of item (0 based) to jump to.- Throws:
Exception
- Allows implementations to throw checked exceptions for interpretation by the framework
-