alibaba / fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
Apache License 2.0
25.74k stars 6.5k forks source link

1.2.83 是不是默认关闭了 Feature.DisableFieldSmartMatch? #4209

Open venusdrogon opened 2 years ago

venusdrogon commented 2 years ago

1. 背景

bean


import com.alibaba.fastjson.annotation.JSONField;

import lombok.Data;

@Data
public class RadiosConfig{

    /**
     * 电台类型:1-国家台,2-省市台,3-网络台
     */
    @JSONField(name = "radio_type")
    private Byte radioType;
}

json 字符串 和单元测试

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;
import com.feilong.json.JsonUtil;

/**
 * 
 * @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
 */
public class RadiosConfigTest{

    private static final Logger LOGGER = LoggerFactory.getLogger(RadiosConfigTest.class);

    /** <code>{@value}</code> */
    public static final String  str    = "{\"radioType\":2}";

    @Test
    public void test(){
        RadiosConfig parseObject = JSONObject.parseObject(str, RadiosConfig.class);

        LOGGER.debug(JsonUtil.format(parseObject));
    }
}

2. 结果

fastjson 1.2.83

16:02:07 DEBUG (RadiosConfigTest.java:41) test() - {"radioType": null}

fastjson 1.2.70

16:06:33 DEBUG (RadiosConfigTest.java:41) test() - {"radioType": 2}
wangweijie1021 commented 2 years ago

升级后需要加上alternateNames属性,@JSONField(name="别名", alternateNames="原属性名")

wenshao commented 2 years ago

这个,这个是行为改变

venusdrogon commented 2 years ago

这个,这个是行为改变

感觉好坑