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

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

c++ - No viable overloaded operator for references a map -

java - UML - How would you draw a try catch in a sequence diagram? -