如何制作Eclipselink的moxy marshal HashMap <String,String>?

Sal*_*lil 4 jersey java-ee moxy

当我的jersey应用程序中的方法返回HashMap时,我得到以下异常

[Exception [EclipseLink-25003] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred marshalling the object
Internal Exception: Exception [EclipseLink-25007] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A descriptor for class java.util.HashMap was not found in the project.  For JAXB, if the JAXBContext was bootstrapped using TypeMappingInfo[] you must call a marshal method that accepts TypeMappingInfo as an input parameter.]
Run Code Online (Sandbox Code Playgroud)

问题的方法是:

@PUT
@Path("/subscriptions/{id}")
@Produces("application/json")
public Map<String, String> updateSubscription(@PathParam("id") int id) {
  Map<String, String> response = new HashMap<String, String>();
  response.put("status", "ok");
  return response;
}
Run Code Online (Sandbox Code Playgroud)

Moxy在我的应用程序中与POJO很好地配合.所以,我猜它处理HashMap足够聪明.

bdo*_*han 5

注意: 我是EclipseLink JAXB(MOXy)的负责人,也是JAXB(JSR-222)专家组的成员.

MOXyJsonProvider目前不支持根级别Map.我刚刚检查了EclipseLink 2.5.2和2.6.0流的修复程序,因此isReadable/ isWriteable将为这些类型返回false,以便MOXy不会被选为此用例的JSON绑定提供程序.您可以从2013年10月11日开始从以下链接下载每晚构建:

我还输入了以下增强请求,以便为Map添加提供一流的支持: