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

shade.com.alibaba.fastjson2.writer.ObjectWriterImplBigDecimal Maven / Gradle / Ivy

There is a newer version: 1.3.7
Show newest version
package com.alibaba.fastjson2.writer;

import com.alibaba.fastjson2.JSONWriter;

import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.function.Function;

final class ObjectWriterImplBigDecimal
        extends ObjectWriterPrimitiveImpl {
    static final ObjectWriterImplBigDecimal INSTANCE = new ObjectWriterImplBigDecimal(null, null);

    private final DecimalFormat format;

    final Function function;

    public ObjectWriterImplBigDecimal(DecimalFormat format, Function function) {
        this.format = format;
        this.function = function;
    }

    @Override
    public void writeJSONB(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
        BigDecimal decimal;
        if (function != null && object != null) {
            decimal = function.apply(object);
        } else {
            decimal = (BigDecimal) object;
        }
        jsonWriter.writeDecimal(decimal, features, format);
    }

    @Override
    public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
        BigDecimal decimal;
        if (function != null && object != null) {
            decimal = function.apply(object);
        } else {
            decimal = (BigDecimal) object;
        }

        jsonWriter.writeDecimal(decimal, features, format);
    }

    public Function getFunction() {
        return function;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy