title: Spring Data Rest projection for Embedded Entities
body: <p>Lets assume I have the following entities:</p>
  
  <pre><code>@Entity
  public class Registration {
  
      @ManyToOne
      private Student student;
      //getters, setters
  }
  
  @Entity
  public class Student {
  
      private String id;
      private String userName;
      private String name;
      private String surname;
      //getters, setters
  }
  
  @Projection(name="minimal", types = {Registration.class, Student.class})
  public interface RegistrationProjection {
  
      String getUserName();
      Student getStudent();
  
  }
  </code></pre>
  
  <p>I'm trying to create the following JSON representation, So when I use <code>http://localhost:8080/api/registrations?projection=minimal</code> I dont need all the user data to come along:</p>
  
  <pre><code>{
    "_links": {
      "self": {
        "href": "http://localhost:8080/api/registrations{?page,size,sort,projection}",
      }
    },
    "_embedded": {
      "registrations": [
        {
          "student": {
            "userName": "user1"
          }
        }
      ],
      "_links": {
        "self": {
          "href": "http://localhost:8080/api/registrations/1{?projection}",
        }
      }
    }
  }
  </code></pre>
  
  <p>However the Projection I have created I get an exception(it works without the getUserName() statement. Obviously I have defined the interface in the wrong way...but which is the correct way to do something like this?</p>
  
  <p>EDIT: Exception is the following</p>
  
  <pre><code>Invalid property &amp;#39;userName&amp;#39; of bean class [com.test.Registration]: 
  Could not find field for property during fallback access! (through reference chain: org.springframework.hateoas.PagedResources[&amp;quot;_embedded&amp;quot;]
  -&amp;gt;java.util.UnmodifiableMap[&amp;quot;registrations&amp;quot;]-&amp;gt;java.util.ArrayList[0]-&amp;gt;org.springframework.data.rest.webmvc.json.[&amp;quot;content&amp;quot;]
  -&amp;gt;$Proxy119[&amp;quot;userName&amp;quot;])&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>