Weedoze Weedoze - 4 months ago 20
JSON Question

Java API - List<int[]> to JSON error

My REST API should return a list of objects

pubic List<MyObject> getMyObjects(){...}


public class MyObject {

private int id;
private String name;
private List<int[]> coordinates;


The call on this method works and there is no error.

The problem is about list of coordinates. When generating the JSON my list of int[] is transformed into this

"coordinates":["[I@409cd27c","[I@1a552b8c","[I@1af3f13d","[I@5e12856b","[I@78bba3e7", //...

How can I make the JSON transformation work with this list ? Everything is working fine with other variable.


You're getting, exactly as expected, the toString() of those int[]s. Ideally, you should encapsulate the bare coordinate pairs into a Point class, but if that's not practical because of other requirements about the JSON, use a list instead of an array:

List<List<Integer>> coordinates;