All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.fastjson2.reader.FieldReaderAtomicReferenceField Maven / Gradle / Ivy

Go to download

Fastjson is a JSON processor (JSON parser + JSON generator) written in Java

There is a newer version: 2.0.53.android8
Show newest version
package com.alibaba.fastjson2.reader;

import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.schema.JSONSchema;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.concurrent.atomic.AtomicReference;

final class FieldReaderAtomicReferenceField
        extends FieldReaderAtomicReference {
    final boolean readOnly;

    FieldReaderAtomicReferenceField(
            String fieldName,
            Type fieldType,
            Class fieldClass,
            int ordinal,
            String format,
            JSONSchema schema,
            Field field) {
        super(fieldName, fieldType, fieldClass, ordinal, 0, format, schema, null, field);

        readOnly = Modifier.isFinal(field.getModifiers());
    }

    @Override
    public boolean isReadOnly() {
        return true;
    }

    @Override
    public void accept(T object, Object value) {
        if (value == null) {
            return;
        }

        try {
            if (readOnly) {
                AtomicReference atomic = (AtomicReference) field.get(object);
                atomic.set(value);
            } else {
                field.set(
                        object,
                        new AtomicReference(value));
            }
        } catch (Exception e) {
            throw new JSONException("set " + fieldName + " error", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy