- Boon - Home
- Boon - Overview
- Boon - Environment Setup
- Parsing JSON
- Boon - To Object
- Boon - To Map
- Boon - Sources
- Generating JSON
- Boon - From Object
- Boon - From Map
- Date Handling
- Boon - Long To Date
- Boon - String To Date
- Boon - Generating Date
- Annotations
- Boon - @JsonIgnore
- Boon - @JsonInclude
- Boon - @JsonViews
- Boon - @JsonProperty
- Boon Useful Resources
- Boon - Quick Guide
- Boon - Useful Resources
- Boon - Discussion
Boon - @JsonViews
@JsonViews is used to control values to be serialized or not.
Example - @JsonView
Following example is for @JsonView −
import org.boon.json.JsonSerializer;
import org.boon.json.JsonSerializerFactory;
import org.boon.json.annotations.JsonViews;
public class BoonTester {
public static void main(String args[]) {
JsonSerializer serializerPublic = new JsonSerializerFactory()
.useAnnotations()
.setView( "public" )
.create();
JsonSerializer serializerInternal = new JsonSerializerFactory()
.useAnnotations()
.setView( "internal" )
.create();
Student student = new Student(1,"Mark", 20);
String jsonString = serializerPublic.serialize( student ).toString();
System.out.println(jsonString);
jsonString = serializerInternal.serialize( student ).toString();
System.out.println(jsonString);
}
}
class Student {
public int id;
public String name;
@JsonViews( ignoreWithViews = {"public"}, includeWithViews = {"internal"})
public 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