0

我正在尝试使用带有 @POST 注释的 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

4

1 回答 1

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 的错误。

于 2013-03-27T09:37:33.837 回答