我有一个对象“A”,当对象“A”被序列化时,它扩展了对象“B”,对象“B”中的字段没有被序列化为 JSON。有任何想法吗?这是我所涉及的对象。
public class CreateNewPlayerAndLoginResponse extends EPNetResponse{
private PlayerSession playerSession;
public CreateNewPlayerAndLoginResponse() {
}
public CreateNewPlayerAndLoginResponse(Integer playerId, String playerSessionId) {
this.playerSession = new PlayerSession(playerId, playerSessionId);
}
public CreateNewPlayerAndLoginResponse(EPNetErrorEnum error) {
super(error);
}
public CreateNewPlayerAndLoginResponse(EPNetError error) {
super(error);
}
public PlayerSession getPlayerSession() {
return playerSession;
}
public void setPlayerSession(PlayerSession playerSession) {
this.playerSession = playerSession;
}
@Override
public String toString() {
return "CreateNewPlayerAndLoginResponse{" + "playerSession=" + playerSession + '}';
}
}
public class EPNetResponse implements Serializable{
private EPNetError error;
public EPNetResponse() {
}
public EPNetResponse(EPNetError error) {
this.error = error;
}
public EPNetResponse(EPNetErrorEnum error){
this.error = new EPNetError(error);
}
public EPNetError getError() {
return error;
}
public void setError(EPNetError error) {
this.error = error;
}
@JsonIgnore
public boolean isError(){
if(error == null){
return false;
}
return true;
}
}
public class EPNetError implements Serializable{
private static final int UNEXPECTED_ERROR = 5417;
private Integer code;
private String message;
public EPNetError() {
}
public EPNetError(EPNetErrorEnum error){
this.code = error.getCode();
this.message = error.getMessage();
}
public EPNetError(EPNetErrorEnum error, String message){
this.code = error.getCode();
this.message = message;
}
public EPNetError(String message){
this.code = EPNetError.UNEXPECTED_ERROR;
this.message = message;
}
public EPNetError(Integer code, String message) {
this.code = code;
this.message = message;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
我得到的序列化响应是
{"playerSession":null}
即使我 100% 确定在序列化之前对象的错误消息部分。
另外值得一提的是,我使用的是 Jackson 1.9.2 和 Jersey 1.13