java - Best way to use Json object from @requestBody in controller instead of mapping to POJO -
usually map object @requestbody pojo @ controller. in order map pojo should know fields @requestbody object. so, question best way use object inside controller if don't know fields inside requestbody.
is like?
@requestmapping(value = "/students", method = requestmethod.post, consumes = "application/json") public @responsebody student getstudent(@requestbody string json) { // parse json string object... }
please share innovative ideas. in advance.
updated answer
based on updated description of question , if using jackson following code give map of json string.
objectmapper mapper = new objectmapper(); map<string,object> map = mapper.readvalue(json, map.class);
note: have created new instance of objectmapper
, can use objectmapper bean if have defined 1 application.
Comments
Post a Comment