package com.changhu.support.fastjson2.deserialze;

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

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

/**
 * author: luozhun
 * desc: LatitudeDeserializer
 * createTime: 2023/8/26 16:10
 */
public class LatitudeDeserializer implements ObjectReader<Latitude> {

    public static final LatitudeDeserializer instance = new LatitudeDeserializer();

    private LatitudeDeserializer() {
    }

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