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

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

Go to download

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

The newest version!
package com.alibaba.fastjson2.reader;

import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.util.TypeUtils;

import java.lang.reflect.Method;
import java.util.function.ObjIntConsumer;

final class FieldReaderInt32ValueFunc
        extends FieldReader {
    final ObjIntConsumer function;

    public FieldReaderInt32ValueFunc(String fieldName, int ordinal, Integer defaultValue, Method method, ObjIntConsumer function) {
        super(fieldName, int.class, int.class, ordinal, 0, null, null, defaultValue, method, null);
        this.function = function;
    }

    @Override
    public void accept(T object, int value) {
        function.accept(object, value);
    }

    @Override
    public void accept(T object, long value) {
        function.accept(object, (int) value);
    }

    @Override
    public void accept(T object, Object value) {
        int intValue = TypeUtils.toIntValue(value);
        function.accept(object, intValue);
    }

    @Override
    public void readFieldValue(JSONReader jsonReader, T object) {
        int value = jsonReader.readInt32Value();
        function.accept(object, value);
    }

    @Override
    public Object readFieldValue(JSONReader jsonReader) {
        return jsonReader.readInt32Value();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy