Json 使用jersey和自定义对象作为响应的ClassCastException
我得到一个ClassCastExceptionJson 使用jersey和自定义对象作为响应的ClassCastException,json,jakarta-ee,jersey,Json,Jakarta 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(RegistrationRespon
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();
}
我的服务器返回了一个字符串,我忘了上传带有最新jar的服务器。一旦我这么做了,ClassCastException就消失了
public IRegistrationResponse getRegistrationResponse() {
return ((IRegistrationResponse) super.getMessage());
}
public interface IRegistrationResponse {
public String getIdentityHash() ;
public String getSessionKey() ;
}