Kevin,
I just pushed a very basic renderer extension to
https://github.com/HalBuilder/halbuilder-siren
With this, one can create the RepresentationFactory and add Siren
support:
DefaultRepresentationFactory rf = new
DefaultRepresentationFactory();
rf.withFlag(RepresentationFactory.PRETTY_PRINT);
rf.withRenderer("application/vnd.siren+json",
SirenRepresentationWriter.class);
Then create a representation, with nested representations:
Representation rep =
rf.newRepresentation("/api/user/mark").withProperty("name", "Mark");
rep.withLink("licence",
"http://www.apache.org/licenses/LICENSE-2.0.html");
Representation address = rf.newRepresentation()
.withProperty("city", "Auckland")
.withProperty("country", "New Zealand");
rep.withRepresentation("address", address);
Then convert to a String in the desired media type:
System.out.println(rep.toString("application/vnd.siren+json"));
which yields:
{
"links" : [ {
"rel" : [ "self" ],
"href" : "/api/user/mark"
}, {
"rel" : [ "licence" ],
"href" :
"http://www.apache.org/licenses/LICENSE-2.0.html"
} ],
"properties" : {
"name" : "Mark"
},
"entities" : [ {
"rel" : [ "address" ],
"properties" : {
"city" : "Auckland",
"country" : "New Zealand"
}
} ]
}
Currently it lacks support for multiple rel items ( as required by Hal
), and doesn't support the top level "class" attribute or actions yet. I
thinking they could just be modeled as a specific 'property' with a key
of say 'urn:halbuilder:siren:class' or an embedded representation using
'urn:halbuilder:siren:action' ( I already use this URN scheme for my
flags like pretty print ).
But already, this will let me generate both hal+basic siren without
changing client code ( other than the bootstrap of RepresentationFactory
).
Writing the parser/deserializer may take a bit longer/more-thought at
requires some basic API changes of HalBuilder, but shouldn't be that
difficult.
Mark