简体   繁体   English

凯撒关系与不同类型?

[英]Katharsis relationship with different types?

I would like to deal with JSON that can be either: 我想处理的JSON可以是:

{
  "data": {
    "id": "1",
    "type": "permissions",
    "attributes": { "permission": "VIEW" }
    "relationships": {
      "user": { "data": { "id": "U1", "type": "users" } }
      "resource": { "data": { "id": "G1", "type": "groups" } }
    }
  }
}

OR 要么

{
  "data": {
    "id": "1",
    "type": "permissions",
    "attributes": { "permission": "VIEW" }
    "relationships": {
      "user": { "data": { "id": "U1", "type": "users" } }
      "resource": { "data": { "id": "P1", "type": "pages" } }
    }
  }
}

That is, I would like the "resource" relationship type to be entirely customizable ("groups" or "pages" or anything else). 也就是说,我希望“资源”关系类型是完全可定制的(“组”或“页面”或其他任何类型)。

Is there a way to do that with Katharsis? 有没有办法用Katharsis做到这一点? I was hoping for some kind of inheritance... 我希望有某种继承...

@JsonApiResource(type = "permissions")
public class Permission {
  ...
  @JsonApiToOne
  private SharedResource resource;
  ...
}

public interface SharedResource {
  ...
}

@JsonApiResource(type = "pages")
public class Page implements SharedResource {
  ...
}

But that doesn't work completely. 但这并不能完全起作用。 I've finagled it enough where a findAll returns pretty well (though the links don't reflect the type "pages"), but any POST with the relationships set returns a 405 Method Not Allowed. 我已经找到足够的findAll,它的findAll返回的效果很好(尽管链接没有反映类型“ pages”),但是任何设置了关系的POST都返回405 Method Not Allowed。

Not sure it's possible, but I'd really like it to be since I like Katharsis. 不确定是否有可能,但是我真的很希望这样,因为我喜欢Katharsis。

I think what you're referring to is polymorphic entity types. 我认为您指的是多态实体类型。 If so, this has been asked for repeatedly but currently doesn't exist. 如果是这样,则已多次要求此请求,但当前不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM