Boon - @JsonInclude

@JsonInclude służy do dołączania właściwości mających wartości null / puste lub domyślne. Domyślnie Boon ignoruje takie właściwości podczas serializacji / deserializacji.

Przykład - @JsonInclude

Poniższy przykład dotyczy @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;
   }
}

Wynik

Po pomyślnym uruchomieniu skryptu zobaczysz następujące dane wyjściowe -

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