Returning Map<T, List<V>> as a JSON from Spring. Map key elements do not parse into JSON format -
i have question connected returning map<t, list<v>>
json response.
i have spring server returns json objects, i'm exploring problem returning map
in format. want return map<t, list<v>>
server json , display in form this:
-t.name: { v.somefield1 = ..., v.somefield2 = ..., . . }, { v.somefield1 = ..., v.somefield2 = ..., . . }, -t.name: { ... } ....
i have @onetomany
relation between objects t
, v
. return in way, apart t
objects - jackson return object t
not json, full package/path t
class in project, [app.something.tobject.class]
. cannot access field there.
should try cast object jsonobject
example before i'll send (i think stupid)? have no idea why jackson parse objects in list , return them in json format , not change key objects t
json.
any ideas or solutions how resolve problem?
edit: maybe @ this first.
well, had same problem today , did creating dto:
public class class mydto { public t key; public list<v> values; }
and convert that:
@get // etc. public list<mydto> getmymap() { list<mydto> mydtolist = new arraylist<>(); for(t key : mymap.keys()) { mydto mydto = new mydto(); mydto.key = key; mydto.values = mymap.get(key); } return mydtolist; }
i don't know if there better way. i'd glad know myself if there was. appears there way little different.
Comments
Post a Comment