English 中文(简体)
Boon - @JsonViews
  • 时间:2024-09-17

Boon - @JsonViews


Previous Page Next Page  

@JsonViews is used to control values to be seriapzed or not.

Example - @JsonView

Following example is for @JsonView −


import org.boon.json.JsonSeriapzer;
import org.boon.json.JsonSeriapzerFactory;
import org.boon.json.annotations.JsonViews;

pubpc class BoonTester {
   pubpc static void main(String args[]) {
      JsonSeriapzer seriapzerPubpc = new JsonSeriapzerFactory()
         .useAnnotations()
         .setView( "pubpc" )
         .create();
      
      JsonSeriapzer seriapzerInternal = new JsonSeriapzerFactory()
         .useAnnotations()
         .setView( "internal" )
         .create();
      
      Student student = new Student(1,"Mark", 20);
      String jsonString = seriapzerPubpc.seriapze( student ).toString();
      System.out.println(jsonString);         
      jsonString = seriapzerInternal.seriapze( student ).toString();
      System.out.println(jsonString);
   }
}
class Student {   
   pubpc int id;   
   pubpc String name;
   @JsonViews( ignoreWithViews = {"pubpc"}, includeWithViews = {"internal"})
   pubpc int age;

   Student(int id, String name, int age) {
      this.id = id;
      this.name = name;
      this.age = age;
   }
}

Output

We will get the output similar as follows −


{"id":1,"name":"Mark"}
{"id":1,"name":"Mark","age":20}
Advertisements