私は、ジャージを使用して、JAVAでRESTWebサービスを構築しました。MediaTypeをapplication_xmlからapplication_jsonに切り替えるまで、すべてが正常に機能していました。
XMLを使用している場合は、すべてが正常に機能します。
クライアント側:
public static CoResponse rO = new CoResponse();
rO = service.path("check-in").accept(MediaType.APPLICATION_XML).put(CoResponse.class, rO);
サーバ側:
@PUT
@Consumes(MediaType.APPLICATION_XML)
public CoResponse newCheckin(JAXBElement<CoResponse> obj){
CoResponse newObj = obj.getValue();
//DO SOMETHING....
return newObj
}
MediaTypeをApplication_JSONに変更すると、415のサポートされていないタイプのエラーが発生します。
クライアント側:
public static CoResponse rO = new CoResponse();
rO = service.path("check-in").accept(MediaType.APPLICATION_JSON).put(CoResponse.class, rO);
サーバ側:
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public CoResponse newCheckin(JAXBElement<CoResponse> obj){
CoResponse newObj = obj.getValue();
//DO SOMETHING....
return newObj
}
JSONを使用するときに他に何かすることはありますか?ありがとうございました。
私が使用したクラスは次のとおりです。
CoResponseオブジェクト:
@XmlRootElement
public class CoResponse {
private int code;
private String errorMessage;
//Datastore
public CoDataList<CoDataMap<String, String>> data = new CoDataList<CoDataMap<String, String>>();
}
CoDataListオブジェクト:
public class CoDataList <V> implements Map<Integer, V>{
int nextIndex;
public Map<Integer, V> data = new HashMap<Integer,V>();
}
CoDataMapオブジェクト:
public class CoDataMap <K, V> implements Map<K, V>{
public Map<K, V> data = new HashMap<K,V>();
}