ObjectMapper class can also be used to parse a JSON to Map object instead of a POJO object.
Example
The following example is using ObjectMapper class to parse a JSON string 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\":\"Zafrul\", \"age\":21}"; Map studentMap = mapper.readValue(jsonString, Map.class); System.out.println("Name: " + studentMap.get("name")); System.out.println("Age: " + studentMap.get("age")); } }
Output
The output is given below −
Name: Zafrul Age: 21
Next Topic:-Click Here