9
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}