Spring Serializing Embedded Data with ManyToOne

I have an interesting problem. My data model is this:

Type A:

@Entity @JsonIgnoreProperties(ignoreUnknown = true) public class A { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; } 

Type B:

 @Entity @JsonIgnoreProperties(ignoreUnknown = true) public class B { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; } 

Embedded C:

 @Embeddable @JsonIgnoreProperties(ignoreUnknown = true) public class C { @ManyToOne private A a; @ManyToOne private B b; } 

And type D:

 @Entity @JsonIgnoreProperties(ignoreUnknown = true) public class D { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ElementCollection @OrderColumn(name = "ORDER_INDEX") @CollectionTable( name = "d_c_join", joinColumns = @JoinColumn(name = "d_id") ) private List<C> listOfC; } 

The de-initialization (and storage) of objects works fine. When an object of class D is serialized, the result is as follows:

 { "_embedded" : { "ds" : [ { "id" : 1, "listOfC" : [ { }, { } ], "_links" : { "self" : { "href" : "http://localhost:8000/ds/1" } } } ] } } 

How to configure Spring-Data to serialize A and B in C (their URIs would be best).

+7
spring-data spring-data-jpa spring-data-rest spring-hateoas hateoas
source share
1 answer

I'm pretty sure you're looking for Projections . I don't think Spring will serialize reference collections without it.

See my answer here for more details: Spring Sending data-Rest POST to a sub-resource

+3
source share

All Articles