我想处理 JSON,它可以是:
{
"data": {
"id": "1",
"type": "permissions",
"attributes": { "permission": "VIEW" }
"relationships": {
"user": { "data": { "id": "U1", "type": "users" } }
"resource": { "data": { "id": "G1", "type": "groups" } }
}
}
}
或者
{
"data": {
"id": "1",
"type": "permissions",
"attributes": { "permission": "VIEW" }
"relationships": {
"user": { "data": { "id": "U1", "type": "users" } }
"resource": { "data": { "id": "P1", "type": "pages" } }
}
}
}
也就是说,我希望“资源”关系类型是完全可定制的(“组”或“页面”或其他任何东西)。
有没有办法用 Katharsis 做到这一点?我希望得到某种继承...
@JsonApiResource(type = "permissions")
public class Permission {
...
@JsonApiToOne
private SharedResource resource;
...
}
public interface SharedResource {
...
}
@JsonApiResource(type = "pages")
public class Page implements SharedResource {
...
}
但这并不完全有效。我已经在 findAll 返回很好的地方(尽管链接不反映“页面”类型),但任何带有关系集的 POST 都会返回 405 Method Not Allowed。
不确定这是否可能,但我真的很喜欢它,因为我喜欢 Katharsis。