jsonld-java icon indicating copy to clipboard operation
jsonld-java copied to clipboard

Getting expanded JSON-LD message in Jackson's Tree Model

Open mBread opened this issue 11 years ago • 2 comments

Is it possible, with the jsonld-java library as-is or with minimal changes, to get the results of an expand() operation in the style of Jackson's Tree Model?

At the moment I'm having to keep checking instanceof (List or Map) and casting at every level of the data, which makes the code very verbose. However, if I had a Jackson JsonNode, which uses the null object pattern for calls to path() (Jackson calls null objects "missing node" objects) then I don't need instanceof, casting or even null checks. This could make my code a lot more concise and less error-prone.

(An alternative would be a new JSON-LD specific wrapper/subclass, e.g. JsonLdNode, that followed the same pattern as Jackson's JsonNode. This could then include methods such as isBlankNode(), isSubject(), isArray(), islist(), etc from JsonLdUtils. I know I could have a go at writing this myself, and if I don't have time others are unlikely to have time, but I just thought I'd include the idea.)

mBread avatar Jan 29 '14 13:01 mBread

We are using Jackson already so it isn't a big change there, however, we are using readValueAs right now, instead of readTree.

https://github.com/jsonld-java/jsonld-java/blob/master/core/src/main/java/com/github/jsonldjava/utils/JSONUtils.java#L67

Ideally we would convert all of the "Object" typed parameters to use JsonNode or similar when we work on that.

Now that the spec is stable, we definitely want to explore ways to make the API smoother and more efficient.

When you have time, definitely try to have a go at modifying some methods to suit your use case and then open a pull request to get a peer review, even if the code is not complete.

ansell avatar Jan 29 '14 22:01 ansell

:+1:

ceefour avatar Nov 12 '14 11:11 ceefour