I am trying to call web API using spring-boot and webclient. web api is of graph ql. so I am passing parameters using JsonObject as following.
JSONObject variables = new JSONObject();
JSONObject docParam = new JSONObject();
try {
docParam.put("id", 0);
docParam.put("name", metadata.get("resourceName"));
docParam.put("type", metadata.get("Content-Type"));
docParam.put("datasourceId", 5);
variables.put("document", docParam);
} catch (Exception e) {
}
LinkedMultiValueMap<String, Object> formData = new LinkedMultiValueMap<String, Object>();
formData.add("query", "mutation ($document: Document, $projectId: Int!) { addDocument { id } }");
formData.add("variables", variables);
WebClient webClient = WebClient.builder().baseUrl("https://localhost:44375/api/graph")
.clientConnector(new ReactorClientHttpConnector(httpClient)).build();
webClient.post().contentType(MediaType.APPLICATION_JSON_UTF8).syncBody(formData).retrieve()
.bodyToMono(String.class).subscribe(response -> {
Extract.saveProcessedFile(response);
});
I am getting following error when webclient call is sent.
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.util.LinkedMultiValueMap["variables"]->java.util.LinkedList[0])
It looks like an issue if you look into the following discussion which is exactly matching your scenario.
https://github.com/lukas-krecan/JsonUnit/issues/41
To quote below,
Exception in thread "main" java.lang.IllegalArgumentException: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
When using like
JSONObject object = new JSONObject(); object.put("abx","xyz"); JSONObject object1 = new JSONObject(); object1.put("qwe","rty"); CustomMatcher.assertThat(object, JsonMatchers.jsonEquals(object1));
Lucas mentioned that it should be fixed as per the below statement.
Thanks for feedback. Should be fixed in 1.14.1
I know that it may not resolve your problem, it is for your reference. Hopefully you can use higher version for trial.
将JSONObject
转换为JsonObject
对我JsonObject
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.