
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert JSON Array to List Using Jackson in Java
A Jackson is a Java-based library and it can be useful to convert Java objects to JSON and JSON to Java Object. A Jackson API is faster than other API, needs less memory area and is good for the large objects. We can convert a JSON array to a list using the ObjectMapper class. It has a useful method readValue() which takes a JSON string and converts it to the object class specified in the second argument.
Example
import java.util.*; import com.fasterxml.jackson.databind.*; public class JSONArrayToListTest1 { public static void main(String args[]) { String jsonStr = "[\"INDIA\", \"AUSTRALIA\", \"ENGLAND\", \"SOUTH AFRICA\", \"WEST INDIES\"]"; ObjectMapper objectMapper = new ObjectMapper(); try { List<String> countries = objectMapper.readValue(jsonStr, List.class); System.out.println("The countries are:\n " + countries); } catch(Exception e) { e.printStackTrace(); } } }
Output
The countries are: [INDIA, AUSTRALIA, ENGLAND, SOUTH AFRICA, WEST INDIES]
Advertisements