Re: HalBuilder

67 views
Skip to first unread message

Mark Derricutt

unread,
Mar 23, 2014, 2:24:00 AM3/23/14
to Paul Cox, halbuil...@googlegroups.com

Hi Paul,

Sorry for not responding to this sooner.

Sadly what you've hit upon is expected behaviour, as far as HalBuilder is (currently) concerned.

Originally I wrote the library with roundtripping of JSON/XML in mind, and thus was only supporting simple key/value properties, however as people actually started using the library, and very few people seem to care about the XML variant or round-tripping support, I broke up the library into separate artefacts for the various representation formats and have taken..... liberties with how the underlying Jackson is configured to allow the serialisation of nested/complex objects, but as yet not not looked at the reading side of things.

On the reading side - I also have the "render as java interface" which was novel, from a simple API perspective but also kinda horrible.

For a while I've known I've needed to address this, but as yet haven't a) had the time or b) personal need - but as more and more people seem to be wanting it, I think I need to act - I've had a few pull requests over the last year that attempt to implement support for it, but also break things as far as the interface-rendering goes.

I've been thinking about ways around this for awhile - and think the following approach might be a good way forward:

  • Deprecate the Interface-Rendering code, in favour of what will come below
  • Introduce JSON and XML specific representation subclasses that store the original String/byte[] that they read from an InputStream and exposing that to anyone who wants to parse the original contents for more rich content, whilst still parsing out the _link's and _embedded's as normal.
  • Since the original content is available, Interface Rendering can now use that to create full object hierarchies as the user sees fit, without needed to use reflection/proxies.
  • This also minimises exposing JDOM and Jackson APIs to the end user - the fact I use Jackson internally shouldn't matter ( I'm tempted to look at moving to Boon actually ).

In theory - these changes shouldn't actually take that long to do as its just moving a few things around internally.

Thoughts?

On 12 Mar 2014, at 2:01, Paul Cox wrote:

Hi Mark,

I'm trying to use your java halbuilder and I'm having a problem:

When I build a readable representation based on a hal response like below,
I get null in the properties field for test.

String string3 = "{\"_links\":[],\"test\":{\"testing\":\"testing2\"}}";

Am I doing something wrong, is it a bug, or is it actually expected
behaviour?

I appreciate any help you can give.

Cheers,
Paul

p.s. the actual code is

RepresentationFactory representationFactory = new
DefaultRepresentationFactory().withReader(RepresentationFactory.HAL_JSON,
JsonRepresentationReader.class);

ReadableRepresentation readableRepresentation =
representationFactory.readRepresentation(new StringReader(string3));

Reply all
Reply to author
Forward
0 new messages