Weekly Learning, Spring Data + REST

About me, I’m a terrible writer. I’m horrible at spelling. I want to change that. I want to sound smarter when I conduct myself on the internet, and in emails around my office.

We had a standard email that we, as developers would send to each other every Friday. The developer who enforced it has left. So now we’ve abandoned that. I still need my writing fix.

Welcome to me, in weekly format. No proof reading, type and shoot style. If anyone ever sees this. Please review, critique, and all around destroy and disprove everything I write.

This week

So, what did I discover this week? The power of Java Spring.

Here is a great walk-through using React + Spring Boot

But, the example is non-functioning. Here’s the complete one.

Beyond

Using UUIDs as the Primary ID, heres an example from an Entity

@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "uuid", unique = true)
private String id;

Its output

{
"_embedded" : {
"employees" : [ {
"firstName" : "Frodo",
"lastName" : "Baggins",
"description" : "ring bearer",
"_links" : {
"self" : {
"href" : "http://localhost:8080/api/employees/ff80818152b3511b0152b35125500000"
},
"employee" : {
"href" : "http://localhost:8080/api/employees/ff80818152b3511b0152b35125500000"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/api/employees"
},
"profile" : {
"href" : "http://localhost:8080/api/profile/employees"
}
}
}

Spring Data REST follows the REST principles strictly. When you return the data you’ll notice you're not returning the id field. That is because it goes against the standard practices of REST.

Resource-Based Individual resources are identified in requests using URIs as resource identifiers. The resources themselves are conceptually separate from the representations that are returned to the client. For example, the server does not send its database, but rather, some HTML, XML or JSON that represents some database records expressed, for instance, in Finnish and encoded in UTF-8, depending on the details of the request and the server implementation.

If you're looking to expose the Id here is a StackOverflow answer, but you’ll be breaking the standards. You savages!

http://stackoverflow.com/questions/24839760/spring-boot-responsebody-doesnt-serialize-entity-id