首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >com.fasterxml.jackson.databind.exc.InvalidDefinitionException

com.fasterxml.jackson.databind.exc.InvalidDefinitionException
EN

Stack Overflow用户
提问于 2019-06-08 09:46:55
回答 2查看 1.5K关注 0票数 0

我试图使用spring和webclient调用web。web为图ql。因此,我使用JsonObject传递参数,如下所示。

代码语言:javascript
运行
复制
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调用时,我将收到以下错误。

代码语言:javascript
运行
复制
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])
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-10 16:27:21

JSONObject转换为JsonObject为我工作。

票数 0
EN

Stack Overflow用户

发布于 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内

我知道这可能不能解决你的问题,这是供你参考的。希望你能用更高的版本来试用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56505225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档