Boon 简明教程

Boon - @JsonInclude

@JsonInclude 用于包含具有 null/空或默认值 的属性。默认情况下,Boon 在序列化/反序列化期间会忽略此类属性。

Example - @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;
   }
}

Output

当脚本成功运行时,您将看到以下输出 −

{"id":1,"name":null}