2013-03-25 52 views
0

我想通过@POST注释将两个复杂对象作为参数传递给RestEasy。RestEasy:可以发布两个复杂对象吗?

@POST 
@Path("/save") 
@Consumes("application/json") 
public void save(ComplexeObjectAleph objectAleph, ComplexeObjectBeth objectBeth); 

只有一个参数是还好吧,但是有两个 - 我得到异常:

Caused by: java.io.EOFException: No content to map to Object due to end of input 
    at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2775) 
    at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2691) 
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315) 
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419) 
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105) 
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:63) 
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108) 
    at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:169) 
    at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:136) 
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:159) 
    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257) 
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222) 
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211) 
    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:542) 
    ... 22 more 

的例子:https://github.com/markstein/de.mosst/tree/master/PlayareaRestEasy

+0

你不能那样做。见细节:http://stackoverflow.com/questions/5553218/jax-rs-post-multiple-objects – 2013-03-26 22:13:14

+0

当然!我可以做这个。看到黄色的答案。 – Mark 2013-03-27 09:49:18

回答

0

这是可能的,但细心。

这两个参数必须用@Form加注释。

@Path("playarea") 
public interface PlayareaRsInterface { 

    @POST 
    @Path("save") 
    @Produces(MediaType.APPLICATION_JSON) 
    public void save(@Form ComplexeObjectAleph objectAleph, @Form ComplexeObjectBeth objectBeth); 

} 

和两个类的属性必须有@FormParam(...)注释:

public class ComplexeObjectAleph { 

    @FormParam("aleph") 
    public String aleph; 

} 

public class ComplexeObjectBeth { 

    @FormParam("beth") 
    public String beth; 

} 

但要小心的@FormParam(...)值必须是不平等的,否则RestEasy的无法正确解析数据。可能是RestEasy的bug。