我试图使用spring和webclient调用web。web为图ql。因此,我使用JsonObject传递参数,如下所示。
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);
});
当发送webclient调用时,我将收到以下错误。
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])
发布于 2019-06-10 16:27:21
将JSONObject
转换为JsonObject
为我工作。
发布于 2019-06-08 10:33:59
如果您查看下面的讨论,它看起来是一个与您的场景完全匹配的问题。
https://github.com/lukas-krecan/JsonUnit/issues/41
引证如下,
线程“主”java.lang.IllegalArgumentException中的异常:没有为类org.json.JSONObject找到序列化程序,也没有发现创建BeanSerializer的属性(为了避免异常,禁用SerializationFeature.FAIL_ON_EMPTY_BEANS) 当使用喜欢时 JSONObject object =新JSONObject();object.put("abx","xyz");JSONObject object1 =新JSONObject();object1.put("qwe","rty");CustomMatcher.assertThat(object,JsonMatchers.jsonEquals(object1));
卢卡斯说,它应该按照下面的声明进行修正。
谢谢你的反馈。应固定在1.14.1内
我知道这可能不能解决你的问题,这是供你参考的。希望你能用更高的版本来试用。
https://stackoverflow.com/questions/56505225
复制相似问题