How to reference an entity with inheritance in Spring Data REST when POSTing new entity?

前端 未结 3 1572
我寻月下人不归
我寻月下人不归 2021-01-13 08:07

I have entities with joined inheritance:

Supporter

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Js         


        
3条回答
  •  太阳男子
    2021-01-13 08:41

    Just another workaround using a RelProvider:

    1. Do not use @JsonTypeInfo
    2. Create a RelProvider for SupporterEntity sub-classes

      @Component
      @Order(Ordered.HIGHEST_PRECEDENCE)
      public class SupporterEntityRelProvider implements RelProvider {
      
        @Override
        public String getCollectionResourceRelFor(final Class type) {
          return "supporters";
        }
      
        @Override
        public String getItemResourceRelFor(final Class type) {
          return "supporter";
        }
      
        @Override
        public boolean supports(final Class delimiter) {
          return org.apache.commons.lang3.ClassUtils.isAssignable(delimiter, SupporterEntity.class);
        }
      }
      

    See also:

    • https://jira.spring.io/browse/DATAREST-344
    • http://docs.spring.io/spring-hateoas/docs/current/reference/html/#configuration.at-enable

提交回复
热议问题