JAX-RS ベースの RESTful Web サービスを開発しようとしており、Web サービスの JSON 応答を自動的に生成するために MOXy (JAXB) を使用しています。
すべてがクールですが、Web サービスは JavaScript ベースの Web アプリケーションのバックエンドになるため、一般にアクセス可能になるため、クラス名などの特定の詳細を公開したくありません。
しかし、特定の条件下では、MOXy が "@type" エントリをマーシャリングされた文字列に埋め込み、このエントリの後にマーシャリングされたばかりのオブジェクトのクラス名が続くことに気付きました。
特に、拡張クラスのインスタンスをマーシャリングするときに、MOXy がこのように動作することに気付きました。
次のスーパークラス「MyBasicResponse」を仮定します
@XmlRootElement(name="res")
public class MyBasicResponse {
@XmlElement
private String msg;
public MyBasicResponse() {
// Just for conformity
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
そして、この特化(拡張)クラス「MySpecialResponse」
@XmlRootElement(name="res")
public class MySpecialResponse extends MyBasicResponse {
@XmlElement
private String moreInfo;
public MySpecialResponse() {
// Just for conformity
}
public String getMoreInfo() {
return moreInfo;
}
public void setMoreInfo(String moreInfo) {
this.moreInfo = moreInfo;
}
}
したがって、MyBasicResponse オブジェクトのマーシャリングされた文字列は次のとおりです。
{"msg":"A Message."}
(大丈夫!)
しかし、MySpecialResponse オブジェクトのマーシャリングされた文字列は次のようになります。
{"@type":"MySpecialResponse","msg":"A Message.","moreInfo":"More Information."}
剥がす方法はありますか
"@type":"MySpecialResponse"
私の応答のうち?