Package org.springframework.batch.item.json

# 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>`

public class JacksonJsonObjectReader<T> extends Object implements JsonObjectReader<T>
Implementation of `JsonObjectReader` based on Jackson.

Since:
  4.1
Author:
  Mahmoud Ben Hassine

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JacksonJsonObjectReader(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<? extends T> itemType)`
  `JacksonJsonObjectReader(Class<? extends T> itemType)`
  Create a new `JacksonJsonObjectReader` instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Close the input resource.
  `void`
  `open(org.springframework.core.io.Resource resource)`
  Open the Json resource for reading.
  `T`
  `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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### JacksonJsonObjectReader

    public JacksonJsonObjectReader(Class<? extends T> itemType)
    Create a new `JacksonJsonObjectReader` instance.
    Parameters:
      `itemType` - the target item type

  - ### JacksonJsonObjectReader

    public JacksonJsonObjectReader(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<? extends T> itemType)

- ## 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:
      - `JacksonJsonObjectReader(ObjectMapper, Class)`

  - ### open

    public void open(org.springframework.core.io.Resource resource) throws Exception
    Description copied from interface: `JsonObjectReader`
    Open the Json resource for reading.
    Specified by:
      `open` in interface `JsonObjectReader<T>`
    Parameters:
      `resource` - the input resource
    Throws:
      `Exception` - if unable to open the resource

  - ### read

    @Nullable public T read() throws Exception
    Description copied from interface: `JsonObjectReader`
    Read the next object in the Json resource if any.
    Specified by:
      `read` in interface `JsonObjectReader<T>`
    Returns:
      the next object or `null` if the resource is exhausted
    Throws:
      `Exception` - if unable to read the next object

  - ### close

    public void close() throws Exception
    Description copied from interface: `JsonObjectReader`
    Close the input resource.
    Specified by:
      `close` in interface `JsonObjectReader<T>`
    Throws:
      `Exception` - if unable to close the input resource