json - Jackson mapper with generic class in scala -
i trying serialise generalresponse
:
case class generalresponse[t](succeeded: boolean, payload: option[t])
and payload groupsforuserresult
:
case class groupsforuserresult(groups: seq[uuid]).
i using mapper.readvalue(response.body, classof[generalresponse[groupsforuserresult]])
unfortunately payload serialised map
, not desired case class (groupforuserresult
).
because of java erasure - jackson can't know @ runtime generic type t line -
mapper.readvalue(response.body, classof[generalresponse[groupsforuserresult]])
a solution problem
mapper.readvalue(json, new typereference[generalresponse[groupsforuserresult]] {})
this way provide instance of typereference
needed type information.
Comments
Post a Comment