java - 如何在 Spring Data Rest 中隐藏 _embedded 实体字段
问题描述
我运行基于Spring Boot Gradle Plugin的 SDR 应用程序。我最近从2.1.9.RELEASE升级到2.2.0.RELEASE。在没有 100% 确定这就是原因的情况下,SDR 现在似乎_embedded
为每个资源公开了一个附加字段。新字段包含相关实体的数据。
例如,这是一个使用2.1.9.RELEASE公开的资源:
{
"uuid": "77315176-cb4f-4126-8e8b-9007457a7ce1",
"name": "root",
"_links": {
"self": {
"href": "localhost/users/1"
},
"user": {
"href": "localhost/users/1"
},
"group": {
"href": "localhost/users/1/group"
}
}
}
与2.2.0.RELEASE公开的相同资源:
{
"uuid": "77315176-cb4f-4126-8e8b-9007457a7ce1",
"name": "root",
"_embedded": {
"group": {
"uuid": "be43382c-7b03-4d28-9597-7284986f700b",
"name": "admin"
}
},
"_links": {
"self": {
"href": "localhost/users/1"
},
"user": {
"href": "localhost/users/1"
},
"group": {
"href": "localhost/users/1/group"
}
}
}
如果没有证据,我假设有以下缺点:
- 它大大增加了响应大小。我可以理解在某些用例中需要这些额外的数据,但是,在这种情况下,我更喜欢根据需要通过制作投影来手动公开它。
- 为了收集额外暴露的数据,需要额外的数据库事务,这会对性能产生负面影响。
- 默认情况下会公开更多公共 API,需要维护。同样,我更喜欢使用Projections以尽可能减少响应。
这是我的问题:
- 是否可以恢复以前的 API 格式,例如自定义新功能或完全关闭它?
- 我想知道这个设计的目的是什么。鉴于上述假设的缺点,新功能有哪些优势?
解决方案
原来是Spring Data Rest 错误。版本2.2.1.RELEASE包含一个修复程序,它恢复了通常的行为。
推荐阅读
- regex - 如何定义正则表达式/正则表达式并通过 Prolog 将其实现为自动机?
- c# - AddForce 到本地变换
- apache-kafka - Confluent Kafka docker 容器无法启动
- java - Kafka Java客户端等待节点分配超时
- python - django模板中ObjectId和字符串的连接
- machine-learning - 3d 数据集的深度学习,准备管道的最佳方法是什么?哪种算法最好?
- html - 如何将重叠的图像留在同一位置?
- stream - 切换标签时流广告停止,如何防止?
- python - 从 Json Geocodio API 中提取文本
- google-cloud-platform - BigQuery 公共数据集 geolite2.ipv4_city_blocks 似乎丢失了