- Boon 教程
- Boon - 主页
- Boon - 概览
- Boon - 环境设置
- 解析 JSON
- Boon - 转换为对象
- Boon - 转换为映射
- Boon - 源
- 生成 JSON
- Boon - 从对象
- Boon - 从映射
- 日期处理
- Boon - Long 与 Date
- Boon - String 与 Date
- Boon - 生成日期
- 注解
- Boon - @JsonIgnore
- Boon - @JsonInclude
- Boon - @JsonViews
- Boon - @JsonProperty
- Boon 实用资源
- Boon - 快速指南
- Boon - 实用资源
- Boon - 讨论
Boon - @JsonProperty
@JsonProperty 用于标记非常规 getter/setter 方法与 json 属性一起使用。
@JsonProperty 示例
下面的示例适用于 @JsonProperty −
import org.boon.json.JsonFactory;
import org.boon.json.ObjectMapper;
import org.boon.json.annotations.JsonProperty;
public class BoonTester {
public static void main(String args[]) {
ObjectMapper mapper = JsonFactory.create();
Student student = new Student(1);
String jsonString = mapper.writeValueAsString(student);
System.out.println(jsonString);
}
}
class Student {
private int id;
Student(){}
Student(int id){
this.id = id;
}
@JsonProperty("id")
public int getTheId() {
return id;
}
@JsonProperty("id")
public void setTheId(int id) {
this.id = id;
}
}
输出
运行后,您会看到以下输出 −
{"id":1}
广告