HalBuilder / halbuilder-json

HalBuilder JSON Support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JsonRepresentationReader does not return links

dennisstritzke opened this issue · comments

If you call representationReader.read(reader); with an HAL compliant JSON structure you can't access the link objects via representation.getLinkByRel("books").

Internaly the read function calls readLinks function in JsonRepresentationReader. At the second line the function tries to get an Iterator with all fields of the links. (rootNode.get(LINKS).fields()). This nerver works because the method fields() method of the ArrayNode class isn't overridden (FasterXML jackson-databind Issue).

Oh yay :( Will add a test and fix this and push out another release over the weekend.

Ok this is no bug with FasterXML jackson-databind, I misunderstood the terminology. Because fields are Key/Value pairs and now its clear that an Array is not a field.

But rootNode.get(LINKS).iterator() should fix it.

Gah - github somehow lost my comment. I can't seem to reproduce this. I added another test case assertion that calls getLinksByRel which seems to work fine. rootNode.get(LINKS) returns an ObjectNode which does have fields() implemented ( its a map from rel to either an link object, or an array of link objects).

Can you post a sample JSON resource which is tripping up this problem?

Unfortunately my Toyproject is on my computer at work. I will provide you this Information on Monday morning.

Looking at my JSON test data, I realize that I am not using the proposed JSON format. Instead I use the slightly different approach with Atom Pub as JSON of Spring Data REST.

The main difference is that, there isn't an object as child of the "links" attribute, but an array of objects of "rel" and "href" values. Now its clear that this isn't a bug of halbuilder-json. Do you think that this kind of JSON representation should be added as Spring Data REST support? If you dont think so, I would fork this part of the project and will do the adaption to fit Spring.

So if I get this right - you're trying to use non-HAL format documents with a HAL document reader? I'm confused as to where "Spring Data REST" comes into play? Do you mean to add this as a new reader/writer similar to the experimental halbuilder-siren Reader/Writer - which is a separate, pluggable project which just implements the required interfaces.

HalBuilder and it's group of modules is primarily targeting the HAL format.

Reading my own post I realize that it is a bit confusing. I'm trying to make it clear.

My first point is that the "bug" isn't a bug, instead its a feature. I used Spring Data REST to produce my JSON Data, but I - at this point - dont realized that this output isn't HAL compliant.

Furthermore I tried to discuss by myself where is the right place to implement the HAL builder features to suit the output produced by Spring Data REST:

  • Modify the JSON rendering of Spring Data REST to be HAL compliant
  • Build a module like halbuilder-siren
  • Fork halbuilder-json and do the manipulation needed

Now I think it's best to modify the JSON rendering of Spring Data REST, because you are totally right that this project should target the HAL format.

btw very nice work done here!