- Boon 教程
- Boon - 主頁
- Boon - 概覽
- Boon - 環境設定
- 解析 JSON
- Boon - 轉換為物件
- Boon - 轉換為 Map
- Boon - 來源
- 生成 JSON
- Boon - 從物件中提取
- Boon - 從 Map 中提取
- 日期處理
- Boon - Long 轉換為日期
- Boon - String 轉換為日期
- Boon - 生成日期
- 註解
- Boon - @JsonIgnore
- Boon - @JsonInclude
- Boon - @JsonViews
- Boon - @JsonProperty
- Boon 有用資源
- Boon - 快速指南
- Boon - 有用資源
- Boon - 討論
Boon - @JsonInclude
@JsonInclude 用於包含具有空值/空值或預設值的屬性。預設情況下,Boon 會在序列化/反序列化期間忽略此類屬性。
示例 - @JsonInclude
以下示例適用於 @JsonInclude −
import org.boon.json.JsonFactory;
import org.boon.json.ObjectMapper;
import org.boon.json.annotations.JsonInclude;
public class BoonTester {
public static void main(String args[]) {
ObjectMapper mapper = JsonFactory.createUseAnnotations( true );
Student student = new Student(1,null);
String jsonString = mapper.writeValueAsString(student);
System.out.println(jsonString);
}
}
class Student {
public int id;
@JsonInclude
public String name;
Student(int id, String name) {
this.id = id;
this.name = name;
}
}
輸出
如果指令碼執行成功,您將看到以下輸出 −
{"id":1,"name":null}
廣告