0

I have this Spring Java class

@Entity
public class Person {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    private String firstName;
    private String lastName;

    //getters and setters here
}

which outputs me following response

{
  "_embedded" : {
    "people" : [ {
      "firstName" : "John",
      "lastName" : "Dean",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8060/people/1"
        },
        "person" : {
          "href" : "http://localhost:8060/people/1"
        }
      }
    },

But I want to see also the id to be to exposed, how to do that?

This didn't help How to expose the resourceId with Spring Data Rest

Simon Schnell
  • 1,160
  • 14
  • 24
  • 1
    A simple solution is to use a DTO and expose your DTO to the outside world. This way you don't couple different layers of your application – sashok_bg Oct 27 '17 at 12:52
  • DTO doesn't sound bad. But might be a little to much. On my vue.js frontend I want also to navigate with those IDs so http://myfrontendip/people/1 so DTO might be a too much – Simon Schnell Oct 27 '17 at 13:03

1 Answers1

2

This guy answered it like I wanted to, thanks for the help.

When using Spring Data REST it has something especially designed for this. There is the notion of Projections and Excerpts with it you can specify what and how you want to return it.

@Projection(name="personSummary", types={Person.class})
public interface PersonSummary {
    String getEmail();
    String getId();
    String getName();
}
Simon Schnell
  • 1,160
  • 14
  • 24