0

我喜欢从一个简单的 Web 服务返回一个 hashmap 对象..但是我无法从客户端获取 hashmap 对象(在我的情况下..它是一个托管 bean)。当我尝试使用以下代码获取该 hashMap 时...

ClientRequest  clientRequest = new ClientRequest("MyserviveURL");
ClientResponse clientResponse = clientRequest.get(new GenericType <HashMap<String, Boolean>>(){});

HashMap myHash = (HashMap<String, Boolean>) clientResponse.getEntity();

我收到类似 Unable to find a MessageBodyReader for HashMap 之类的错误...请帮助我摆脱这个错误。

而且我还想知道从客户端获取 hashmap 对象的最佳方法。它可以通过 xml 或 json

4

1 回答 1

0

如果你使用杰克逊

用户映射器

ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(myHash);

现在将其返回json为“应用程序/json”

于 2013-01-30T10:03:09.867 回答