Package org.ghotibeaun.json.converters
Class AbstractJSONConverter
java.lang.Object
org.ghotibeaun.json.converters.AbstractConverter
org.ghotibeaun.json.converters.AbstractJSONConverter
- All Implemented Interfaces:
Converter
,JSONConverter
public abstract class AbstractJSONConverter extends AbstractConverter implements JSONConverter
-
Constructor Summary
Constructors Constructor Description AbstractJSONConverter(ConverterOption<?>... option)
-
Method Summary
Modifier and Type Method Description abstract <T> T
convertToClass(Class<T> targetClass, JSONObject json)
Convert a JSONObject into a Class instanceabstract <T> List<T>
convertToList(Class<T> targetItemClass, JSONArray array, Optional<ValueConverter<?>> valueConverter)
Deprecated.abstract <T> List<T>
convertToList(JSONArray array, Optional<ValueConverter<?>> valueConverter, Optional<Class<?>> targetClass)
abstract <T> T
convertValue(JSONValue<?> value, Optional<ValueConverter<?>> valueConverter, Optional<Class<?>> targetClass)
static JSONConverter
getJSONConverter(ConverterOption<?>... options)
Methods inherited from class org.ghotibeaun.json.converters.AbstractConverter
copyOptions, getConverterOptions
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.ghotibeaun.json.converters.Converter
getConverterOptions
-
Constructor Details
-
AbstractJSONConverter
-
-
Method Details
-
getJSONConverter
-
convertToClass
public abstract <T> T convertToClass(Class<T> targetClass, JSONObject json) throws JSONConversionExceptionDescription copied from interface:JSONConverter
Convert a JSONObject into a Class instance- Specified by:
convertToClass
in interfaceJSONConverter
- Type Parameters:
T
- the Class type.- Parameters:
targetClass
- the concrete class to instantiate. It must implement or inherit from the Class type.json
- The JSONObject instance containing the data to initialize into the class instance- Returns:
- the specified Class instance
- Throws:
JSONConversionException
- thrown when an error occurs during the conversion
-
convertToList
@Deprecated public abstract <T> List<T> convertToList(Class<T> targetItemClass, JSONArray array, Optional<ValueConverter<?>> valueConverter) throws JSONConversionExceptionDeprecated.Description copied from interface:JSONConverter
Convert a JSONArray into a List of values- Specified by:
convertToList
in interfaceJSONConverter
- Type Parameters:
T
- The Class Type.- Parameters:
targetItemClass
- The concrete class for each item in the list.array
- the JSONArray instance containing the data to initialize the list- Returns:
- a List of values
- Throws:
JSONConversionException
- thrown when an error occurs during conversion
-
convertToList
public abstract <T> List<T> convertToList(JSONArray array, Optional<ValueConverter<?>> valueConverter, Optional<Class<?>> targetClass) throws JSONConversionException- Specified by:
convertToList
in interfaceJSONConverter
- Throws:
JSONConversionException
-
convertValue
public abstract <T> T convertValue(JSONValue<?> value, Optional<ValueConverter<?>> valueConverter, Optional<Class<?>> targetClass) throws JSONConversionException- Specified by:
convertValue
in interfaceJSONConverter
- Throws:
JSONConversionException
-