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}
廣告
© . All rights reserved.