Halbuilder is a simple Java API for generating and consuming HAL documents conforming to the HAL Specification.
Map<String,Object> friend = HashMap.of("name", "Mike", "age", 36);
ResourceRepresentation<Map<String,Object>> owner =
ResourceRepresentation.create("http://example.com/mike", friend)
.withLink("td:friend", "http://example.com/mamund")
Map<String,Object> todoMeta = HashMap.of(
"created_at", "2010-01-16", "updated_at", "2017-06-13",
"summary", "An example list");
ResourceRepresentation<Map<String,Object>> halResource =
ResourceRepresentation.create("http://example.com/todo-list", todoMeta)
.withLink("td:search", "/todo-list/search;{searchterm}")
.withLink("td:description", "/todo-list/description")
.withRepresentation("td:owner", owner);
JsonRepresentationWriter jsonRepresentationWriter =
JsonRepresentationWriter.create();
ByteString representation = jsonRepresentationWriter.print(accountRepWithLinks);
System.out.println(representation.utf8());
JsonRepresentationReader jsonRepresentationReader =
JsonRepresentationReader.create();
ResourceRepresentation<ByteString> representation =
jsonRepresentationReader.read(
new InputStreamReader(Some.class.getResourceAsStream("/test.json")));
// or as a type
ResourceRepresentation<Person> personRepresentation =
jsonRepresentationReader.read(
new InputStreamReader(Some.class.getResourceAsStream("/test.json")),
Person.class);
HalBuilder is deployed to Apache Maven Central under the following coordinates:
<dependency>
<groupId>com.theoryinpractise</groupId>
<artifactId>halbuilder5</artifactId>
<version>5.0.1</version>
</dependency>
More documentation is available from the main website at gotohal.net.
Email support and discussion is available on the development forum.