package com.changhu.support.fastjson2.deserialze;

import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.reader.ObjectReader;
import org.geotools.measure.Longitude;

import java.lang.reflect.Type;
import java.math.BigDecimal;

/**
 * author: luozhun
 * desc: LongitudeDeserializer
 * createTime: 2023/8/26 16:15
 */
public class LongitudeDeserializer implements ObjectReader<Longitude> {

    public static final LongitudeDeserializer instance = new LongitudeDeserializer();

    private LongitudeDeserializer() {
    }

    @Override
    public Longitude readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) {
        //读取为BigDecimal来确保精度和避免浮点数的舍入误差
        BigDecimal value = jsonReader.readBigDecimal();
        if (value == null) {
            return null;
        }
        return new Longitude(value.doubleValue());
    }
}