Using Nested Predictions in Spring Data REST

How to get the expected result below where OrderProjection uses ItemProjection to render items using Spring Data REST

GET / orders / 1? projection = with_items

Projection:

@Projection(name = "summary", types = Item.class) public interface ItemProjection { String getName(); } @Projection(name = "with_item", types = Order.class) public interface OrderProjection { LocalDateTime getOrderedDate(); Status getStatus(); Set<ItemProjection> getItems(); // this is marshalling as Set<Item> (full Item graph) } 

Currently obtained as a conclusion:

 { "status" : "PAYMENT_EXPECTED", "orderedDate" : "2014-11-09T11:33:02.823", "items" : [ { "name" : "Java Chip", "quantity" : 1, "milk" : "SEMI", "size" : "LARGE", "price" : { "currency" : "EUR", "value" : 4.20 } } ], "_links" : { "self" : { "href" : "http://localhost:8080/orders/1{?projection}", "templated" : true }, "restbucks:items" : { "href" : "http://localhost:8080/orders/1/items" }, "curies" : [ { "href" : "http://localhost:8080/alps/{rel}", "name" : "restbucks", "templated" : true } ] } } 

Expected Result:

 { "status" : "PAYMENT_EXPECTED", "orderedDate" : "2014-11-09T11:33:02.823", "items" : [ { "name" : "Java Chip" } ], "_links" : { "self" : { "href" : "http://localhost:8080/orders/1{?projection}", "templated" : true }, "restbucks:items" : { "href" : "http://localhost:8080/orders/1/items" }, "curies" : [ { "href" : "http://localhost:8080/alps/{rel}", "name" : "restbucks", "templated" : true } ] } } 
+6
source share
1 answer

You are working in DATAREST-394 , which has been fixed in a few days and will turn into 2.2.2 and 2.3 RC1. It is already available in snapshots for the indicated versions, without hesitation from them.

+4
source

Source: https://habr.com/ru/post/979265/


All Articles