- Boon Tutorial
- 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 - @JsonProperty
@JsonProperty is used to mark non-standard getter/setter method to be used with respect to json property.
Example - @JsonProperty
Following example is for @JsonProperty −
import org.boon.json.JsonFactory; import org.boon.json.ObjectMapper; import org.boon.json.annotations.JsonProperty; public class BoonTester { public static void main(String args[]) { ObjectMapper mapper = JsonFactory.create(); Student student = new Student(1); String jsonString = mapper.writeValueAsString(student); System.out.println(jsonString); } } class Student { private int id; Student(){} Student(int id){ this.id = id; } @JsonProperty("id") public int getTheId() { return id; } @JsonProperty("id") public void setTheId(int id) { this.id = id; } }
Output
Upon execution, you will receive the following output −
{"id":1}
Advertisements
To Continue Learning Please Login
Login with Google