简体   繁体   English

com.fasterxml.jackson.databind.exc.InvalidDefinitionException

[英]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.

相关问题 com.fasterxml.jackson.databind.exc.InvalidDefinitionException:未找到序列化程序 - com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造实例 - com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of Jackson 添加附加字段到 JSON 抛出 com.fasterxml.jackson.databind.exc.InvalidDefinitionException - Jackson adding additional fields to JSON throws com.fasterxml.jackson.databind.exc.InvalidDefinitionException com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造`org.springframework.web.multipart.MultipartFile`的实例 - com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.springframework.web.multipart.MultipartFile` com.fasterxml.jackson.databind.exc.InvalidDefinitionException对于用户实体的某些REST操作 - com.fasterxml.jackson.databind.exc.InvalidDefinitionException for some REST operations on User entity Quarkus com.fasterxml.jackson.databind.exc.InvalidDefinitionException:未找到 class 的序列化程序 - Quarkus com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造“javax.Z0F635D0E0F3874FFF8B581C132E6C7A7B.bind.bind”的实例 - com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `javax.xml.bind.JAXBElement` java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException - java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造`java.time.LocalDate的实例 - com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.time.LocalDate 在 java 日期格式:com.fasterxml.jackson.databind.exc.InvalidDefinition.timeException:无法构造实例的`LocalDatejava. - in java date format: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.time.LocalDate`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM