T - the type of objects that this ObjectReader can deserializepublic interface ObjectReader<T>
This interface supports various features including:
Example usage:
// Get an ObjectReader for a specific type
ObjectReader<User> reader = JSONFactory.getDefaultObjectReaderProvider().getObjectReader(User.class);
// Read from JSON string
String jsonString = "{\"id\":1,\"name\":\"John\"}";
User user = reader.readObject(JSONReader.of(jsonString));
// Create instance with map data
Map<String, Object> data = new HashMap<>();
data.put("id", 1);
data.put("name", "John");
User user2 = reader.createInstance(data);
| Modifier and Type | Field and Description |
|---|---|
static long |
HASH_TYPE |
static java.lang.String |
VALUE_NAME |
| Modifier and Type | Method and Description |
|---|---|
default T |
accept(T object,
java.util.Map map,
long features)
Accepts field values from a map and populates the specified object instance.
|
default void |
acceptExtra(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object fieldValue)
Accepts extra field data that is not mapped to any specific field in the object.
|
default void |
acceptExtra(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object fieldValue,
long features)
Accepts extra field data that is not mapped to any specific field in the object.
|
default ObjectReader |
autoType(JSONReader.Context context,
long typeHash)
Resolves an ObjectReader for the specified type hash using the JSON reader context.
|
default ObjectReader |
autoType(ObjectReaderProvider provider,
long typeHash)
Resolves an ObjectReader for the specified type hash using the ObjectReaderProvider.
|
default T |
createInstance() |
default T |
createInstance(java.util.Collection collection) |
default T |
createInstance(java.util.Collection collection,
JSONReader.Feature... features) |
default T |
createInstance(java.util.Collection collection,
long features) |
default T |
createInstance(long features) |
default T |
createInstance(java.util.Map map,
JSONReader.Feature... features)
Creates an instance of the object type from a map of field values using the specified features.
|
default T |
createInstance(java.util.Map map,
long features) |
default T |
createInstanceNoneDefaultConstructor(java.util.Map<java.lang.Long,java.lang.Object> values)
Creates an instance of the object type using a non-default constructor with the specified values.
|
default java.util.function.Function |
getBuildFunction()
Gets the build function used to construct the final object instance.
|
default long |
getFeatures()
Gets the features enabled by this ObjectReader.
|
default FieldReader |
getFieldReader(long hashCode)
Gets the FieldReader for the specified field hash code.
|
default FieldReader |
getFieldReader(java.lang.String fieldName)
Gets the FieldReader for the specified field name.
|
default FieldReader |
getFieldReaderLCase(long hashCode)
Gets the FieldReader for the specified field hash code, using lowercase matching.
|
default java.lang.Class<T> |
getObjectClass()
Gets the class of objects that this ObjectReader can deserialize.
|
default java.lang.String |
getTypeKey()
Gets the type key used for auto-type support.
|
default long |
getTypeKeyHash()
Gets the hash code of the type key used for auto-type support.
|
default T |
readArrayMappingJSONBObject(JSONReader jsonReader,
java.lang.reflect.Type fieldType,
java.lang.Object fieldName,
long features)
Reads an object from JSONB format with array mapping.
|
default T |
readArrayMappingObject(JSONReader jsonReader,
java.lang.reflect.Type fieldType,
java.lang.Object fieldName,
long features)
Reads an object from JSON format with array mapping.
|
default T |
readJSONBObject(JSONReader jsonReader,
java.lang.reflect.Type fieldType,
java.lang.Object fieldName,
long features)
Reads an object from JSONB format.
|
default T |
readObject(JSONReader jsonReader)
Reads an object from the specified JSONReader.
|
default T |
readObject(JSONReader jsonReader,
long features)
Reads an object from the specified JSONReader using the provided features.
|
T |
readObject(JSONReader jsonReader,
java.lang.reflect.Type fieldType,
java.lang.Object fieldName,
long features)
Reads an object from the specified JSONReader with the given field type, field name, and features.
|
default T |
readObject(java.lang.String str,
JSONReader.Feature... features)
Reads an object from the specified JSON string using the provided features.
|
default boolean |
setFieldValue(java.lang.Object object,
java.lang.String fieldName,
long fieldNameHashCode,
int value)
Sets the value of a field in the specified object.
|
default boolean |
setFieldValue(java.lang.Object object,
java.lang.String fieldName,
long fieldNameHashCode,
long value)
Sets the value of a field in the specified object.
|
default boolean |
setFieldValue(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object value)
Sets the value of a field in the specified object.
|
static final long HASH_TYPE
static final java.lang.String VALUE_NAME
default T createInstance()
Tjava.lang.UnsupportedOperationException - If the method is not overloaded or otherwisedefault T createInstance(long features)
Tjava.lang.UnsupportedOperationException - If the method is not overloaded or otherwisedefault T createInstance(java.util.Collection collection)
Tjava.lang.UnsupportedOperationException - If the method is not overloaded or otherwisedefault T createInstance(java.util.Collection collection, JSONReader.Feature... features)
Tjava.lang.UnsupportedOperationException - If the method is not overloaded or otherwisedefault T createInstance(java.util.Collection collection, long features)
Tjava.lang.UnsupportedOperationException - If the method is not overloaded or otherwisedefault void acceptExtra(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object fieldValue)
object - the object being deserializedfieldName - the name of the extra fieldfieldValue - the value of the extra fielddefault void acceptExtra(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object fieldValue,
long features)
object - the object being deserializedfieldName - the name of the extra fieldfieldValue - the value of the extra fieldfeatures - the JSON reader features to usedefault T createInstance(java.util.Map map, JSONReader.Feature... features)
map - the map containing field names and valuesfeatures - the JSON reader features to usedefault T createInstance(java.util.Map map, long features)
TJSONException - If a suitable ObjectReader is not founddefault T accept(T object, java.util.Map map, long features)
object - the object instance to populatemap - the map containing field names and valuesfeatures - the JSON reader features to usedefault T createInstanceNoneDefaultConstructor(java.util.Map<java.lang.Long,java.lang.Object> values)
values - the map of field hash codes to valuesjava.lang.UnsupportedOperationException - if the method is not overloaded or otherwisedefault long getFeatures()
default java.lang.String getTypeKey()
default long getTypeKeyHash()
default java.lang.Class<T> getObjectClass()
default FieldReader getFieldReader(long hashCode)
hashCode - the hash code of the field namedefault FieldReader getFieldReaderLCase(long hashCode)
hashCode - the hash code of the field name (lowercase)default boolean setFieldValue(java.lang.Object object,
java.lang.String fieldName,
long fieldNameHashCode,
int value)
object - the object in which to set the field valuefieldName - the name of the field to setfieldNameHashCode - the hash code of the field namevalue - the integer value to setdefault boolean setFieldValue(java.lang.Object object,
java.lang.String fieldName,
long fieldNameHashCode,
long value)
object - the object in which to set the field valuefieldName - the name of the field to setfieldNameHashCode - the hash code of the field namevalue - the long value to setdefault FieldReader getFieldReader(java.lang.String fieldName)
fieldName - the name of the fielddefault boolean setFieldValue(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object value)
object - the object in which to set the field valuefieldName - the name of the field to setvalue - the object value to setdefault java.util.function.Function getBuildFunction()
default ObjectReader autoType(JSONReader.Context context, long typeHash)
context - the JSON reader contexttypeHash - the hash code of the type namedefault ObjectReader autoType(ObjectReaderProvider provider, long typeHash)
provider - the ObjectReaderProvidertypeHash - the hash code of the type namedefault T readJSONBObject(JSONReader jsonReader, java.lang.reflect.Type fieldType, java.lang.Object fieldName, long features)
jsonReader - the JSONReader to use for parsingfieldType - the type of the field being readfieldName - the name of the field being readfeatures - the features to useJSONException - if a suitable ObjectReader is not founddefault T readArrayMappingJSONBObject(JSONReader jsonReader, java.lang.reflect.Type fieldType, java.lang.Object fieldName, long features)
jsonReader - the JSONReader to use for parsingfieldType - the type of the field being readfieldName - the name of the field being readfeatures - the features to usejava.lang.UnsupportedOperationException - if the method is not overloaded or otherwisedefault T readArrayMappingObject(JSONReader jsonReader, java.lang.reflect.Type fieldType, java.lang.Object fieldName, long features)
jsonReader - the JSONReader to use for parsingfieldType - the type of the field being readfieldName - the name of the field being readfeatures - the features to usejava.lang.UnsupportedOperationException - if the method is not overloaded or otherwisedefault T readObject(java.lang.String str, JSONReader.Feature... features)
str - the JSON string to parsefeatures - the JSON reader features to usedefault T readObject(JSONReader jsonReader)
jsonReader - the JSONReader to use for parsingdefault T readObject(JSONReader jsonReader, long features)
jsonReader - the JSONReader to use for parsingfeatures - the features to useT readObject(JSONReader jsonReader, java.lang.reflect.Type fieldType, java.lang.Object fieldName, long features)
jsonReader - the JSONReader to use for parsingfieldType - the type of the field being readfieldName - the name of the field being readfeatures - the features to useJSONException - if a suitable ObjectReader is not found