-
Notifications
You must be signed in to change notification settings - Fork 547
Closed
Labels
Milestone
Description
问题描述
当枚举的属性使用了 JsonProperties 注解时,fastjson2序列化结果错误。
输出结果
fastjson2序列化结果:{"dataType":"String"}
jackjson序列化结果:{"dataType":"STRING"}环境信息
- 版本信息:Fastjson2 2.0.59
- 版本信息:Jackson 2.13.4.2
重现步骤
测试代码:
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
public class Fastjson2Test {
private DataType dataType;
@Test
public void test() throws JsonProcessingException {
final Fastjson2Test json2Test = new Fastjson2Test();
json2Test.setDataType(DataType.STRING);
System.out.println("fastjson2序列化结果:" + JSON.toJSONString(json2Test));
ObjectMapper objectMapper = new ObjectMapper();
System.out.println("jackjson序列化结果:" + objectMapper.writeValueAsString(json2Test));
}
public enum DataType {
STRING("String"),
NUMBER("Number");
@JsonProperty
private String code;
DataType(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
public DataType getDataType() {
return dataType;
}
public void setDataType(DataType dataType) {
this.dataType = dataType;
}
}