Class GsonJsonObjectReader<T>
- java.lang.Object
- org.springframework.batch.item.json.GsonJsonObjectReader<T>
- Type Parameters:
T- type of the target object
- All Implemented Interfaces:
JsonObjectReader<T>
public class GsonJsonObjectReader<T> extends java.lang.Object implements JsonObjectReader<T>
Implementation ofJsonObjectReaderbased on Google Gson.- Since:
- 4.1
- Author:
- Mahmoud Ben Hassine
Constructor Summary
Constructors Constructor Description GsonJsonObjectReader(java.lang.Class<? extends T> itemType)Create a newGsonJsonObjectReaderinstance.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the input resource.voidopen(org.springframework.core.io.Resource resource)Open the Json resource for reading.Tread()Read the next object in the Json resource if any.voidsetMapper(com.google.gson.Gson mapper)Set the object mapper to use to map Json objects to domain objects.
Constructor Detail
GsonJsonObjectReader
public GsonJsonObjectReader(java.lang.Class<? extends T> itemType)
Create a newGsonJsonObjectReaderinstance.- Parameters:
itemType- the target item type
Method Detail
setMapper
public void setMapper(com.google.gson.Gson mapper)
Set the object mapper to use to map Json objects to domain objects.- Parameters:
mapper- the object mapper to use
open
public void open(org.springframework.core.io.Resource resource) throws java.lang.ExceptionDescription copied from interface:JsonObjectReaderOpen the Json resource for reading.- Specified by:
openin interfaceJsonObjectReader<T>- Parameters:
resource- the input resource- Throws:
java.lang.Exception- if unable to open the resource
read
public T read() throws java.lang.Exception
Description copied from interface:JsonObjectReaderRead the next object in the Json resource if any.- Specified by:
readin interfaceJsonObjectReader<T>- Returns:
- the next object or
nullif the resource is exhausted - Throws:
java.lang.Exception- if unable to read the next object
close
public void close() throws java.lang.ExceptionDescription copied from interface:JsonObjectReaderClose the input resource.- Specified by:
closein interfaceJsonObjectReader<T>- Throws:
java.lang.Exception- if unable to close the input resource