- 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 - From Object
ObjectMapper class can be used to generate a json string from an Object.
Example
Following example is using ObjectMapper class to generate a JSON string from a Student Object.
import org.boon.json.JsonFactory; import org.boon.json.ObjectMapper; public class BoonTester { public static void main(String args[]){ ObjectMapper mapper = JsonFactory.create(); Student student = new Student("Mahesh", 21); String jsonString = mapper.writeValueAsString(student); System.out.println(jsonString); } } class Student { public String name; public int age; public Student(String name, int age) { this.name = name; this.age = age; } }
Output
This produces the following output −
{"name":"Mahesh","age":21}
Advertisements
To Continue Learning Please Login
Login with Google