[英]com.fasterxml.jackson.databind.exc.InvalidDefinitionException
I am trying to call web API using spring-boot and webclient. 我试图使用spring-boot和webclient调用web API。 web api is of graph ql.
web api是图ql。 so I am passing parameters using JsonObject as following.
所以我使用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);
});
I am getting following error when webclient call is sent. 发送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])
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 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)
线程“main”中的异常java.lang.IllegalArgumentException:没有为类org.json.JSONObject找到序列化器,也没有发现创建BeanSerializer的属性(为了避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)
When using like
使用时喜欢
JSONObject object = new JSONObject();
JSONObject object = new JSONObject(); object.put("abx","xyz");
object.put( “ABX”, “XYZ”); JSONObject object1 = new JSONObject();
JSONObject object1 = new JSONObject(); object1.put("qwe","rty");
object1.put( “QWE”, “RTY”); CustomMatcher.assertThat(object, JsonMatchers.jsonEquals(object1));
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
应该在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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.