gpt4 book ai didi

java - Rest WS 部分 JSON 响应

转载 作者:行者123 更新时间:2023-11-30 05:51:28 25 4
gpt4 key购买 nike

在写这个问题之前,我尝试了在网上找到的许多帖子。

我希望在我的 REST Web 服务中获得部分 JSON 响应。首先,我尝试返回 JSONArray 但我得到了

"No converter found for return value of type: class org.json.JSONArray"

然后我尝试返回 JSONObject 列表,我得到

"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: java.util.ArrayList[0])"

当我在 application.properties 中将 SerializationFeature.FAIL_ON_EMPTY_BEANS 设置为 false 时,我会得到一个空 JSONObject 列表,例如:{}

我在 GitHub 上与您分享我的代码:https://github.com/AbderrahmenISSA/StockManagement/blob/master/src/main/java/com/stockmgt/controllers/v3/ProductControllerV3.java

最佳答案

在 DTO 中将您不希望检索的属性设置为 null。 (用简单的算法来做)

然后将您的序列化程序配置为不在 json 响应中包含空字段。 (有时这是默认行为)

关于java - Rest WS 部分 JSON 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53834461/

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