繁体   English   中英

com.fasterxml.jackson.databind.exc.InvalidDefinitionException

[英]com.fasterxml.jackson.databind.exc.InvalidDefinitionException

我试图使用spring-boot和webclient调用web API。 web api是图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])

如果您查看以下与您的方案完全匹配的讨论,这看起来是一个问题。

https://github.com/lukas-krecan/JsonUnit/issues/41

在下面引用,

线程“main”中的异常java.lang.IllegalArgumentException:没有为类org.json.JSONObject找到序列化器,也没有发现创建BeanSerializer的属性(为了避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)

使用时喜欢

JSONObject object = new JSONObject(); object.put( “ABX”, “XYZ”); JSONObject object1 = new JSONObject(); object1.put( “QWE”, “RTY”); CustomMatcher.assertThat(object,JsonMatchers.jsonEquals(object1));

卢卡斯提到它应该按照以下声明来修复。

感谢您的反馈。 应该在1.14.1中修复

我知道它可能无法解决您的问题,仅供您参考。 希望您可以使用更高版本进行试用。

JSONObject转换为JsonObject对我JsonObject

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM