Convert JSON Array to List of Long Type in Java

In this example tutorial, we will show you how to convert JSON array to List of Long type in Java.

To example requires Gson dependency.

import java.util.List;
import java.lang.reflect.Type;

public class Example {

	public static void main(String[] args) {
		// Json array data
		String jsonArrayExampleData = "[\"123\",\"456\",\"456\",\"232\"]";

		// creating an object of Gson
		Gson gson = new Gson();

		// Converting to List of Long type
		Type type = new TypeToken<List<Long>>() {
		List<Long> list = gson.fromJson(jsonArrayExampleData, type);



The output of the above example will look like this:

[123, 456, 456, 232]