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