Class GsonJsonObjectUnmarshaller<T>

java.lang.Object
org.springframework.batch.infrastructure.item.json.GsonJsonObjectUnmarshaller<T>
Type Parameters:
T - type of objects to unmarshal
All Implemented Interfaces:
JsonObjectUnmarshaller<T>

public class GsonJsonObjectUnmarshaller<T> extends Object implements JsonObjectUnmarshaller<T>
A json object unmarshaller that uses Google Gson to unmarshal a json representation into an object.
Since:
6.1
Author:
Mahmoud Ben Hassine
  • Constructor Details

    • GsonJsonObjectUnmarshaller

      public GsonJsonObjectUnmarshaller(Class<T> type)
      Create a new GsonJsonObjectUnmarshaller with a default Gson.
      Parameters:
      type - the target type
    • GsonJsonObjectUnmarshaller

      public GsonJsonObjectUnmarshaller(com.google.gson.reflect.TypeToken<T> type)
      Create a new GsonJsonObjectUnmarshaller with a default Gson. Use this constructor for parameterized target types, for example new TypeToken<Map<String, Object>>() {}.
      Parameters:
      type - the target type
    • GsonJsonObjectUnmarshaller

      public GsonJsonObjectUnmarshaller(com.google.gson.Gson gson, Class<T> type)
      Create a new GsonJsonObjectUnmarshaller with the provided Gson.
      Parameters:
      gson - the gson object to use
      type - the target type
    • GsonJsonObjectUnmarshaller

      public GsonJsonObjectUnmarshaller(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<T> type)
      Create a new GsonJsonObjectUnmarshaller with the provided Gson. Use this constructor for parameterized target types, for example new TypeToken<Map<String, Object>>() {}.
      Parameters:
      gson - the gson object to use
      type - the target type
  • Method Details

    • unmarshal

      public T unmarshal(String json)
      Unmarshal the provided json into an object of the target type.
      Specified by:
      unmarshal in interface JsonObjectUnmarshaller<T>
      Parameters:
      json - the json representation of the object
      Returns:
      the unmarshalled object
      Throws:
      ParseException - if the json cannot be unmarshalled