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> TconvertToClass(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> TconvertValue(JSONValue<?> value, Optional<ValueConverter<?>> valueConverter, Optional<Class<?>> targetClass)static JSONConvertergetJSONConverter(ConverterOption<?>... options)Methods inherited from class org.ghotibeaun.json.converters.AbstractConverter
copyOptions, getConverterOptionsMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:JSONConverterConvert a JSONObject into a Class instance- Specified by:
convertToClassin 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:JSONConverterConvert a JSONArray into a List of values- Specified by:
convertToListin 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:
convertToListin interfaceJSONConverter- Throws:
JSONConversionException
-
convertValue
public abstract <T> T convertValue(JSONValue<?> value, Optional<ValueConverter<?>> valueConverter, Optional<Class<?>> targetClass) throws JSONConversionException- Specified by:
convertValuein interfaceJSONConverter- Throws:
JSONConversionException
-