- 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}
廣告