Fastjson
这玩意儿不多说,Alibaba出品,出过几次严重的安全漏洞,但是依然很流行。这里写一下它怎么处理枚举。
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
序列化为name()值
默认就是,啥也不用动
import com.alibaba.fastjson.JSON;
enum Gender {
BOY, GIRL, UNKNOW
}
class User {
private Integer id;
private Gender gender;
public User() {
}
public User(Integer id, Gender gender) {
super();
this.id = id;
this.gender = gender;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
}
public class MainTest {
public static void main(String[] args) throws Exception {
// 序列化为JSON输出
User user = new User<