Weedoze
Weedoze

Reputation: 13943

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

My REST API should return a list of objects

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

MyObject

public class MyObject {

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

    // getters
    // setters
}

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.

Upvotes: 1

Views: 90

Answers (1)

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;

Upvotes: 5

Related Questions