0
我@ RepositoryRestResource的collectionResourceRel属性不被服从
@RepositoryRestResource(collectionResourceRel = "tools")
public interface ToolRepository extends MongoRepository<Tool, Long>
工具的MongoRepository可以是2个实现一个:
public class Screwdriver extends Tool
public class Hammer extends Tool
工具使用@JsonTypeInfo
@JsonTypeInfo(use =
com.fasterxml.jackson.annotation.JsonTypeInfo.Id.CLASS, include =
As.PROPERTY, property = "_class")
public abstract class Tool
映射当我做toolRepository.findAll()
这将返回一个JSON响应:
{
"_embedded" : {
"screwdrivers" : [ {
"name" : "Screwdriver",
...
} ],
"hammers" : [ {
"name" : "Hammer",
...
}
}
预期的反应应该是:
{
"_embedded" : {
"tools" : [ {
"name" : "Screwdriver",
...
},
{
"name" : "Hammer",
...
}
}
的collectionResourceRel
不被服从用于使用JSON映射数据类中
进一步调查; (在Spring中)要求确保如果ResourceMetadata缓存中没有这些工具子类的条目,则使用TypeBasedCollectionResourceMapping
,这会导致每个类在json响应中都有其自己的条目。
有没有告诉春天数据休息一个特定的子类应该绑定到特定的资源库,在这种情况下的方式会告诉他春天数据的方式休息那把螺丝刀是ToolRepository
的一部分,因此应该使用这个存储库的collectionResourceRel
?
非常感谢 - '@ RestResource'似乎有诀窍。有些讨厌的是必须将注释添加到我的所有子类中(我比上面多了几个),但它将我的问题排除在外。再次感谢您 –
忽略上述注意事项 - 将注释添加到假设的“工具”类中可以避免我必须将其添加到所有子类的问题,因此完美答案。 –
@ alex.p在我的代码中确认相同的行为。谢谢Alex!我会纠正我的答案...... – Cepr0