后端处理前端NaN导致报错

用实体接参数时,属性类型是Double,前端传NaN会报错,做了简单处理,记录一下,当然前端不传NaN就更好了…

package cn.edu.oa.jsonSerializer;

import cn.micro.framework.exception.BusinessException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.lang.reflect.Field;

public class NaNDeserializer extends JsonDeserializer {

    @Override
    public Object deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        try {
            if (jsonParser != null && StringUtils.isNotEmpty(jsonParser.getText())) {
                if (jsonParser.getText().equals("NaN")) {
                    return null;
                } else {
                    String curr

你可能感兴趣的:(后端处理前端NaN导致报错)