2014-12-08 13 views
6

Come ottenere risultati attesi sotto dove OrderProjection ItemProjection utilizza per elementi di rendering utilizzando primavera dati RESTutilizzando proiezioni annidate in Data primavera REST

GET/ordini/1 di proiezione = with_items

Proiezioni:

@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) 
} 

Attualmente ottenendo come output:

{ 
    "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 
    } ] 
    } 
} 

Expecte d uscita:

{ 
    "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 
    } ] 
    } 
} 
+3

WHOA! Non sapevo di essere autorizzato a specificare le interfacce di proiezione all'interno delle proiezioni! È menzionato da qualche parte nei documenti? –

risposta

4

si sta eseguendo in DATAREST-394 che è stato fissato un paio di giorni un andare e sarà fare in 2.2.2 e 2.3 RC1. È già disponibile nelle istantanee per le suddette versioni, sentiti libero di dare loro un giro.

+0

Grazie Oliver, ho usato 2.3.0.BUILD-SNAPSHOT per spring-data-rest-webmvc e questo risolve il problema REST ma con anche 4.1.2.RELEASE per spring-framework-bom, sto trovando che tutti i miei vecchi URL associati con @RequestMapping da Spring MVC stanno dando errore 404 – fortm

+0

ben 404 stava accadendo a causa della mancata scansione dei componenti nel contesto MVC. <2.2.1 Rilascio dei dati primaverili, questo tuttavia ha funzionato da Scansione componenti dal contesto dell'applicazione – fortm

+1

Questo problema riappare in 2.3.0.M1 per Spring Data Rest, spero che sia solo perché è la versione milestone. – fortm

Problemi correlati