
hydraql.shaded.fastjson2.reader.FieldReaderObjectField Maven / Gradle / Ivy
package hydraql.shaded.fastjson2.reader;
import hydraql.shaded.fastjson2.JSONException;
import hydraql.shaded.fastjson2.JSONReader;
import hydraql.shaded.fastjson2.schema.JSONSchema;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
class FieldReaderObjectField
extends FieldReaderObject {
FieldReaderObjectField(
String fieldName,
Type fieldType,
Class fieldClass,
int ordinal,
long features,
String format,
Object defaultValue,
JSONSchema schema,
Field field) {
super(fieldName, fieldType == null ? field.getType() : fieldType, fieldClass, ordinal, features, format, null, defaultValue, schema, null, field, null);
}
@Override
public void accept(T object, boolean value) {
if (schema != null) {
schema.assertValidate(value);
}
try {
field.setBoolean(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
@Override
public void accept(T object, byte value) {
if (schema != null) {
schema.assertValidate(value);
}
try {
field.setByte(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
@Override
public void accept(T object, short value) {
if (schema != null) {
schema.assertValidate(value);
}
try {
field.setShort(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
@Override
public void accept(T object, int value) {
if (schema != null) {
schema.assertValidate(value);
}
try {
field.setInt(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
@Override
public void accept(T object, long value) {
if (schema != null) {
schema.assertValidate(value);
}
try {
field.setLong(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
@Override
public void accept(T object, float value) {
if (schema != null) {
schema.assertValidate(value);
}
try {
field.setFloat(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
@Override
public void accept(T object, double value) {
if (schema != null) {
schema.assertValidate(value);
}
try {
field.setDouble(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
@Override
public void accept(T object, char value) {
if (schema != null) {
schema.assertValidate(value);
}
try {
field.setChar(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
@Override
public void accept(T object, Object value) {
if (schema != null) {
schema.assertValidate(value);
}
if (value == null && (features & JSONReader.Feature.IgnoreSetNullValue.mask) != 0) {
return;
}
try {
field.set(object, value);
} catch (Exception e) {
throw new JSONException("set " + fieldName + " error", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy