简体   繁体   中英

Jersy Rest service to accept java.util.Map for MediaType.APPLICATION_JSON

I have written a Jersey rest service which accepts java.util.Map as input for example

@POST
@Path("validate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String validate(Map<String,String> data) throws Exception 

And from UI post Response structure is:

{"data":{"abcd":"5210","two":"5173"}}

Server gives an issue

"SEVERE: MessageBodyReader not found for media type=application/json; charset=UTF-8, type=class java.util.HashMap, genericType=java.util.HashMap<java.lang.String, java.lang.String>."

How do I fix this issue?

Just need to change that put the Map object in a wrapper class like

class MapWrapper {

private Map data;

}

and from Jersey Client send the JSON string of object of Map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM