3
包含DOM元素JSON格式的請求在我java
應用jersey
REST
客戶端,我想在JSON
格式發送的請求,並請求object
包含Element
。我如何發送使用的球衣REST客戶
當我發送請求與XML
格式一切工作正常,但當試圖發送請求與JSON
格式服務器未能發送請求。
如果我不追加到Document
創建Element
它產生以下錯誤:
com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle
如果我創建Element
並將其追加到一個Document
它產生以下錯誤(doc.appendChild(root);
):
com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError)
這是我創建我的請求的方式對象:
public OTAAirLowFareSearchRS AirLowFareSearch(OTAAirLowFareSearchRQ request) throws Exception {
OTAAirLowFareSearchRS response = new OTAAirLowFareSearchRS();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("TPA_Extension");
doc.appendChild(root); // This the line I mention above that create different errors
Element e = doc.createElement("CUSTOM_VAR");
root.appendChild(e);
e.insertBefore(doc.createTextNode("CUSTOM_VALUE"), e.getLastChild());
TPAExtensionsType tpa = new TPAExtensionsType();
tpa.getAny().add(root);
request.getPOS().getSource().get(0).setTPAExtensions(tpa);
JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
Client client = ClientBuilder.newClient(new ClientConfig(jacksonJsonProvider));
WebTarget target = client.target(GlobalVariable.bus_url).path("AirLowFareSearch");
response = target
.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE),
OTAAirLowFareSearchRS.class);
return response;
}
當我把我的請求,與XML
格式像下面一切正常:
//JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
//Client client = ClientBuilder.newClient(new ClientConfig(jacksonJsonProvider));
Client client = ClientBuilder.newClient();
WebTarget target = client.target(GlobalVariable.bus_url).path("AirLowFareSearch");
response = target
.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(request, MediaType.APPLICATION_XML_TYPE),
OTAAirLowFareSearchRS.class);
當我送不增加Element
我的要求,我可以送JSON
要求太(所以沒有錯誤配置JSON
)。
這也是Open Travel
對象,我也無法改變請求。
請幫幫我。
優秀的解決方案。 –