- Boon 教程
- Boon - 主頁
- Boon - 概述
- Boon - 環境設定
- 分析 JSON
- Boon - 轉換為物件
- Boon - 轉換為對映
- Boon - Source 程式碼
- 生成 JSON
- Boon - 從物件生成
- Boon - 從對映生成
- 日期處理
- Boon - 長整型到日期
- Boon - 字串到日期
- Boon - 生成日期
- 註釋
- Boon - @JsonIgnore
- Boon - @JsonInclude
- Boon - @JsonViews
- Boon - @JsonProperty
- Boon 實用資源
- Boon - 快速指南
- Boon - 實用資源
- Boon - 討論
Boon - @JsonViews
@JsonViews 用於控制要序列化還是不序列化的值。
示例 - @JsonView
以下示例適用於 @JsonView −
import org.boon.json.JsonSerializer;
import org.boon.json.JsonSerializerFactory;
import org.boon.json.annotations.JsonViews;
public class BoonTester {
public static void main(String args[]) {
JsonSerializer serializerPublic = new JsonSerializerFactory()
.useAnnotations()
.setView( "public" )
.create();
JsonSerializer serializerInternal = new JsonSerializerFactory()
.useAnnotations()
.setView( "internal" )
.create();
Student student = new Student(1,"Mark", 20);
String jsonString = serializerPublic.serialize( student ).toString();
System.out.println(jsonString);
jsonString = serializerInternal.serialize( student ).toString();
System.out.println(jsonString);
}
}
class Student {
public int id;
public String name;
@JsonViews( ignoreWithViews = {"public"}, includeWithViews = {"internal"})
public int age;
Student(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
}
輸出
我們將得到類似於以下的輸出 −
{"id":1,"name":"Mark"}
{"id":1,"name":"Mark","age":20}
廣告