Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JorgenRingen/8fadf6094d46b7cdb1a92893de48f123 to your computer and use it in GitHub Desktop.
Save JorgenRingen/8fadf6094d46b7cdb1a92893de48f123 to your computer and use it in GitHub Desktop.
Using Resources.wrap from spring hateoas
@SpringBootApplication
public class WrappedresourcesspringhateoasApplication {
public static void main(String[] args) {
SpringApplication.run(WrappedresourcesspringhateoasApplication.class, args);
}
}
@RestController
class FooController {
/**
* Produces the following format (according to HAL)
*
*{
* "_embedded": {
* "fooList": [
* {
* "msg": "foo"
* },
* {
* "msg": "bar"
* },
* {
* "msg": "baz"
* }
* ]
* }
*}
*
*/
@GetMapping
public ResponseEntity foo() {
return ResponseEntity.ok(Resources.wrap(Arrays.asList(new Foo("foo"), new Foo("bar"), new Foo("baz"))));
}
}
class Foo {
public String msg;
public Foo(String msg) { this.msg = msg; }
public String getMsg() { return msg; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment