MotechJsonReader

public class MotechJsonReader

Class responsible for creating objects from json. It can use InputStream, String or file classpath. This class uses Gson underneath.

See also: Google Gson

Constructors

MotechJsonReader

public MotechJsonReader()

Constructor.

MotechJsonReader

public MotechJsonReader(FieldNamingStrategy fieldNamingStrategy)

Constructor.

Parameters:
  • fieldNamingStrategy – the field naming strategy to be used when deserializing object

Methods

readFromFile

public Object readFromFile(String classpathFile, Type ofType)

Creates object of type ofType from file under given classpath.

Parameters:
  • classpathFile – the file to deserialize
  • ofType – the type of created object
Returns:

object of type ofType

readFromStream

public Object readFromStream(InputStream stream, Type ofType)

Creates object of type ofType from input stream.

Parameters:
  • stream – the stream to deserialize
  • ofType – the type of created object
Returns:

object of type ofType

readFromStreamOnlyExposeAnnotations

public Object readFromStreamOnlyExposeAnnotations(InputStream stream, Type ofType)

Creates object of type ofType from input stream. Will only deserialize fields with Expose annotation.

Parameters:
  • stream – the stream to deserialize
  • ofType – the type of created object
Returns:

object of type ofType

readFromString

public Object readFromString(String text, Type ofType)

Creates object of type ofType from given String.

Parameters:
  • text – the String to deserialize
  • ofType – the type of created object
Returns:

object of type ofType

readFromString

public Object readFromString(String text, Type ofType, Map<Type, Object> typeAdapters)

Creates object of type ofType from given String using user-specified adapters.

Parameters:
  • text – the String to deserialize
  • ofType – the type of created object
  • typeAdapters – custom adapters to use for deserialization
Returns:

object of type ofType

readFromStringOnlyExposeAnnotations

public Object readFromStringOnlyExposeAnnotations(String text, Type ofType)

Creates object of type ofType from given String. Will only deserialize fields with Expose annotation.

Parameters:
  • text – the String to deserialize
  • ofType – the type of created object
Returns:

object of type ofType