- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we convert a JSON array to a list using Jackson in Java?n
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]
- Related Articles
- How can we convert a JSON array to a list using Jackson in Java?
- How to convert a List to JSON array using the Jackson library in Java?
- How can we convert a list to the JSON array in Java?
- How can we change a field name in JSON using Jackson in Java?
- How to convert a JSON to Java Object using the Jackson library in Java?
- How to convert a JSON object to an enum using Jackson in Java?
- Can we convert a Java array to list?
- Can we convert a Java list to array?
- How to convert Java object to JSON using Jackson library?
- How can we convert a JSON string to a JSON object in Java?
- Can we convert a list to an Array in Java?
- Convert CSV to JSON using the Jackson library in Java?
- Convert JSON to/from Map using Jackson library in Java?
- How to convert a JSON array to array using JSON-lib API in Java?
- How can we implement a JSON array using Streaming API in Java?
- How to create a JSON using Jackson Tree Model in Java?

Advertisements