I am using a batch model:
@Entity @Inheritance(strategy=...) @JsonTypeInfo(use= JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @DiscriminatorColumn(name = "type") public abstract class Party { @Column(updatable = false, insertable = false) private String type; ... } @Entity public class Individual extends Party { ... } @Entity class Organization extends Party { ... }
Spring Data REST responds as follows:
{ "_embedded": { "organizations": [ { "type":"Organization", "name": "Foo Enterprises", "_links": { "self": { "href": "http://localhost/organization/2" }, "organization": { "href": "http://localhost/organization/2" } } } ], "individuals": [ { "type":"Individual", "name": "Neil M", "_links": { "self": { "href": "http://localhost/individual/1" }, "individual": { "href": "http://localhost/individual/1" } } } ] } }
But I need him to answer like this:
{ "_embedded": { "parties": [ { "type": "Organization", "name": "Foo Enterprises", "_links": { "self": { "href": "http://localhost/party/2" }, "organization": { "href": "http://localhost/party/2" } } }, { "type": "Individual", "name": "Neil M", "_links": { "self": { "href": "http://localhost/party/1" }, "individual": { "href": "http://localhost/party/1" } } } ] } }
For this, I understand what a custom RelProvider must provide :
@Order(Ordered.HIGHEST_PRECEDENCE) @Component public class MyRelProvider implements RelProvider { public MyRelProvider() {} @Override public String getItemResourceRelFor(Class<?> aClass) { return "party"; } @Override public String getCollectionResourceRelFor(Class<?> aClass) { return "parties"; } @Override public boolean supports(Class<?> aClass) { return aClass.isAssignableFrom(Party.class); } }
I tried to configure it in Application.java:
@SpringBootApplication public class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } @Bean RelProvider myRelProvider() { return new MyRelProvider(); } }
This does not work. It seems that it is not registered or not registered correctly. See http://andreitsibets.blogspot.ca/2014/04/hal-configuration-with-spring-hateoas.html
How can i fix this?