Created
March 8, 2018 11:59
-
-
Save JorgenRingen/8fadf6094d46b7cdb1a92893de48f123 to your computer and use it in GitHub Desktop.
Using Resources.wrap from spring hateoas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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