ClassCastException使用带自定义对象的泽西作为响应

时间:2012-10-23 20:48:59

标签: json java-ee jersey

我收到了ClassCastException

java.lang.ClassCastException: java.lang.String cannot be cast to com.mcruiseon.common.contracts.IRegistrationResponse
    at com.mcruiseon.common.message.response.RegistrationResponse.getRegistrationResponse(RegistrationResponse.java:43)
    at com.mcruiseon.carpool4all.RegistrationService.post(RegistrationService.java:81)

基于泽西岛的服务代码

@POST
@Path ("Request")
@Consumes({ MediaType.APPLICATION_JSON })
public Response post(JAXBElement<ClientIdentityConcrete> element) {
    RegistrationRequest request = new RegistrationRequest((ClientIdentityConcrete)(element.getValue()));
    RegistrationResponse response ;
    try {
        clientSession = new ClientSession(God.mCruiseOnServer) ;
    } catch (InvalidServerDNSorIPException e) {
        e.printStackTrace();
        return Response.serverError().build() ;
    }
    sessionKey = sessionManager.setClientSession(clientSession) ;
    clientSession.setSessionKey(sessionKey) ;

    clientSession.getSendQueue().sendRequest(request) ;
    try {
        response = (RegistrationResponse)clientSession.waitAndGetResponse(request) ;
    } catch (WaitedLongEnoughException e) {
        return Response.serverError().build() ;
    } catch (UnableToResolveResponseException e) {
        return Response.serverError().build() ;
    }

// Getting Exception in line below
    return Response.ok(response.getRegistrationResponse()).build();
}

支持代码

public IRegistrationResponse getRegistrationResponse() {
        return ((IRegistrationResponse) super.getMessage());
    }

public interface IRegistrationResponse {
    public String getIdentityHash() ;
    public String getSessionKey() ;
}

1 个答案:

答案 0 :(得分:0)

我的服务器正在返回一个字符串,我忘了用最新的jar上传我的服务器。一旦我这样做,ClassCastException就消失了。