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

Using hydra-java without Spring

Open mcesar opened this issue 8 years ago • 1 comments

It would be nice to use hydra-java to render responses from a service that uses plain Jax-RS, with Jackson, for example. In that sense, I found out that this can be accomplished if we remove the dependencies on spring from the class 'JacksonHydraModule'. So, If you like, I can send a pull request containing the refactoring of this class, splitting it in two, one with the current code without the spring dependencies and the other as a subclass of the first plus the dependencies on spring. What do you think?

mcesar avatar Aug 27 '15 12:08 mcesar

If you simply want to render beans with json-ld contexts, it might be enough to use the JacksonHydraSerializer from hydra-jsonld (see JacksonHydraSerializerTest for setup) and not to depend on hydra-spring at all. If you want to have hydra affordances in the responses, I would propose a Jax-RS based AffordanceBuilder, which creates an Affordance from Jax-RS annotations. To make this possible, I kept Affordance and the entire affordance package free from spring-webmvc dependencies. Note that spring-hateoas already has a ControllerLinkBuilder for Jax-RS, which also can be used without spring-webmvc, its capabilities to work with affordances are very limited, though. Would you be interested in creating a JaxRsAffordanceBuilder?

A JacksonHydraModule as you propose, without the Resource mixins, wouldn't render any links, but admittedly it would be more convenient to use than setting up the JacksonHydraSerializer. Due to the funny super constructor parameters of SimpleModule it would probably be good to have an abstract base class in hydra-jsonld with the setupModule code and an implementation of it which creates an instance of the module with appropriate constructor args. Today's JacksonHydraModule in hydra-spring could then inherit from the same abstract base class.

If you agreee, I would gladly incorporate your pull request.

dschulten avatar Sep 15 '15 18:09 dschulten