gpt4 book ai didi

java - com.fasterxml.jackson.databind.exc.InvalidDefinitionException

转载 作者:行者123 更新时间:2023-12-02 04:43:05 30 4
gpt4 key购买 nike

我正在尝试使用 spring-boot 和 webclient 调用 Web API。 web api 是 graph 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);
});

发送网络客户端调用时出现以下错误。

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

引用如下,

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)

When using like

JSONObject object = new JSONObject(); object.put("abx","xyz"); JSONObject object1 = new JSONObject(); object1.put("qwe","rty"); CustomMatcher.assertThat(object, JsonMatchers.jsonEquals(object1));

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

Thanks for feedback. Should be fixed in 1.14.1

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

关于java - com.fasterxml.jackson.databind.exc.InvalidDefinitionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56505225/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com