我有以下json结构:
{
"foo" : {
"foo1" : {
"txt" : "val",
"txt1" : "val1",
"txt2" : "val2",
},
"foo2" : {
"txt" : "val",
"txt1" : "val1",
"txt2" : "val2",
}
},
"bar" : {
"bar1": {
"txt" : "val",
"txt1" : "val1",
"txt2" : "val2",
},
"bar2": {
"txt" : "val",
"txt1" : "val1",
"txt2" : "val2",
}
}
}
虽然我有以下pojo:
class Pojo {
String txt;
String txt1;
String txt2;
}
我的resteasy方法看起来像:
@POST
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@Path("/foo")
public void bar(@QueryParam("jsonObj") Map<String,Map<String,Pojo>> jsonObj);
然而,在启动服务器时,我收到以下错误:
java.lang.RuntimeException:找不到需要的构造函数 字符串参数或valueOf()或fromString()方法 公共抽象void上的javax.ws.rs.QueryParam(“jsonObj”) com.foo.FooBar.bar(java.util.Map)for basetype:java.util.Map at at org.jboss.resteasy.core.StringParameterInjector.initialize(StringParameterInjector.java:217) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.StringParameterInjector。(StringParameterInjector.java:61) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.QueryParamInjector。(QueryParamInjector.java:28) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.InjectorFactoryImpl.createParameterExtractor(InjectorFactoryImpl.java:85) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.MethodInjectorImpl。(MethodInjectorImpl.java:42) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.InjectorFactoryImpl.createMethodInjector(InjectorFactoryImpl.java:76) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodInvoker。(ResourceMethodInvoker.java:100) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodRegistry.processMethod(ResourceMethodRegistry.java:280) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodRegistry.register(ResourceMethodRegistry.java:251) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:221) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:193) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:179) 〜[resteasy-jaxrs-3.0.9.Final.jar:na] at org.jboss.resteasy.plugins.spring.SpringBeanProcessor.onApplicationEvent(SpringBeanProcessor.java:486) 〜[resteasy-spring-3.0.9.Final.jar:na] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:96) 〜[spring-context-3.2.8.RELEASE.jar:3.2.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334) 〜[spring-context-3.2.8.RELEASE.jar:3.2.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:948) 〜[spring-context-3.2.8.RELEASE.jar:3.2.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 〜[spring-context-3.2.8.RELEASE.jar:3.2.8.RELEASE] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) 〜[spring-web-3.2.8.RELEASE.jar:3.2.8.RELEASE] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 〜[spring-web-3.2.8.RELEASE.jar:3.2.8.RELEASE] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.8.RELEASE.jar:3.2.8.RELEASE] at org.jboss.resteasy.plugins.spring.SpringContextLoaderListener.contextInitialized(SpringContextLoaderListener.java:48) [resteasy-spring-3.0.9.Final.jar:na] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) [catalina.jar:7.0.47] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) [catalina.jar:7.0.47] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.47] at org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.47] at org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.47] at java.util.concurrent.FutureTask.run(FutureTask.java:262)[na:1.7.0-45] 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0-45] at java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0-45]在java.lang.Thread.run(Thread.java:744)[na:1.7.0-45]
我浏览了documentation,对于复杂对象,它说使用StringConvertor,但不应该支持List,Map等简单类型...
答案 0 :(得分:1)
而不是在Map&gt;中获取JSON; jsonObj格式,您可以使用InputStream然后您可以处理输入流以从中获取对象。