- 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 - Sources
ObjectMapper class can be used to parse a json from varying sources. It can use following sources to parse JSON.
byte Array
char Array
File
Reader classes
Input Stream classes
String
Example
Following example is using ObjectMapper class to parse a JSON char array to a Map Object.
import java.util.Map; import org.boon.json.JsonFactory; import org.boon.json.ObjectMapper; public class BoonTester { public static void main(String args[]){ ObjectMapper mapper = JsonFactory.create(); String jsonString = "{\"name\":\"Mahesh\", \"age\":21}"; char[] jsonCharAray = jsonString.toCharArray(); Map studentMap = mapper.readValue(jsonCharAray, Map.class); System.out.println("Name: " + studentMap.get("name")); System.out.println("Age: " + studentMap.get("age")); } }
Output
You will see the following output −
Name: Mahesh Age: 21
Advertisements