Boon Tutorial
Selected Reading
- Boon - Discussion
- Boon - Useful Resources
- Boon - Quick Guide
- Boon - @JsonProperty
- Boon - @JsonViews
- Boon - @JsonInclude
- Boon - @JsonIgnore
- Boon - Generating Date
- Boon - String To Date
- Boon - Long To Date
- Boon - From Map
- Boon - From Object
- Boon - Sources
- Boon - To Map
- Boon - To Object
- Boon - Environment Setup
- Boon - Overview
- Boon - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Boon - From Object
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; pubpc class BoonTester { pubpc 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 { pubpc String name; pubpc int age; pubpc Student(String name, int age) { this.name = name; this.age = age; } }
Output
This produces the following output −
{"name":"Mahesh","age":21}Advertisements