Junit WebSource类型(Registration.class,register)抛出ClientHandlerException

时间:2012-10-23 04:27:33

标签: json java-ee junit jersey

我正在尝试使用Junit客户端测试基于JSON的Web服务。因为没有no-arg default constructor' on my request object and its super class (AMessageStrategy). When I add the no-arg默认构造函数to both of them the server throws a exception,我得到一个ClientHandlerException没有为类型[simple type,class javax.xml.bind.JAXBElement]找到合适的构造函数:`。这让我陷入困境。

理想情况下,我不想/需要no-arg default constructor。问题是,有没有办法绕过它。我只需要将对象序列化为json。该对象有2个主要字段,消息ID和消息数据。消息数据是一个pojo。

我在请求类上添加了@XmlRootElement(虽然字段上没有注释)。

请指教,我有点卡住了。我是Java EE的新手。如果需要更多信息,请告诉我。

com.sun.jersey.api.client.ClientHandlerException: javax.ws.rs.WebApplicationException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
com.mcruiseon.common.message.request.RegistrationRequest does not have a no-arg default constructor.
    this problem is related to the following location:
        at com.mcruiseon.common.message.request.RegistrationRequest
com.mcruiseon.common.message.AMessageStrategy does not have a no-arg default constructor.
    this problem is related to the following location:
        at com.mcruiseon.common.message.AMessageStrategy
        at com.mcruiseon.common.message.request.RegistrationRequest

    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
    at com.sun.jersey.api.client.Client.handle(Client.java:648)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
    at test.carpool4all.Registration.testPost(Registration.java:74)

1 个答案:

答案 0 :(得分:0)

RegistrationRequest不是POJO。理想情况下,它应该是一个POJO才能工作。

相关问题