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 - To Object
Boon - To Object
ObjectMapper is the main actor class of Boon pbrary. ObjectMapper class provides functionapty for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionapty for performing conversions.
It is also highly customizable to work both with different styles of JSON content, and to support more advanced Object concepts such as polymorphism and Object identity.
Example
Following example is using ObjectMapper class to parse a JSON string to 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(); String jsonString = "{"name":"Mahesh", "age":21}"; Student student = mapper.readValue(jsonString, Student.class); System.out.println(student); } } class Student { private String name; private int age; pubpc Student(){} pubpc String getName() { return name; } pubpc void setName(String name) { this.name = name; } pubpc int getAge() { return age; } pubpc void setAge(int age) { this.age = age; } pubpc String toString(){ return "Student [ name: "+name+", age: "+ age+ " ]"; } }
Output
The output is mentioned below −
Student [ name: Mahesh, age: 21 ]Advertisements