toedter / spring-hateoas-jsonapi

A JSON:API media type implementation for Spring HATEOAS
Apache License 2.0
106 stars 15 forks source link

Could the classes like `JsonApiDocument` be public open and not package-private? #82

Closed Gems closed 8 months ago

Gems commented 10 months ago

Problem

I'm currently working on an project where I'm implementing a generic API that serves as a gateway to a legacy software system. The API needs to expose resources in the JSON:API format. However, due to the nature of the project, I don't have the classes that describe the entities involved because the entities are unknown at the build-time and the definitions are loaded during runtime from a database.

Instead, I'd like to rely on the generic JSON:API models provided by the library, which are currently package-private.

Proposed Solution

I'd like to discuss the possibility of making the classes that represent JSON:API entities public within the library. This would be immensely helpful for projects like mine, where we need to work with JSON:API resources in a generic manner.

I'd appreciate feedback from the maintainers and the community on whether this proposed solution would be acceptable and what the implications might be. If there are concerns or alternative suggestions, please feel free to share your thoughts. Ultimately, I want to ensure that this change aligns with the goals and design principles of the library while addressing the specific needs of projects like mine.

Thank you for your time and consideration.

toedter commented 8 months ago

Hi Eduard, sorry for responding late. The current architecture is to use the generic HATOAS representation models when possible and the builder for JSON:API specific features. The class JsonApiDocument is an implementation detail that should not provide public API.

What is the concrete problem you have to solve, maybe there is another solution,

Gems commented 8 months ago

Hi Kai, No worries, it was a PoC, so I tinkered with the necessary custom code, and it sufficed.

The problem I was solving was to generate a JSON:API resource from the data represented as Map<String, Object> (not a concrete class that I can provide annotations for). I reckoned that having a library that helps to build a valid JSON:API resource is better than generating everything from scratch. I like your library because of its simplicity, but it doesn't allow leveraging the low-level API it's based on.

I hope it's clearer now.

toedter commented 8 months ago

Ah, now I understand.

A possible solution for you problem would be to use the @JsonAnyGetter annotation. You could create a wrapper object for your map. Take a look at https://www.tutorialspoint.com/jackson_annotations/jackson_annotations_jsonanygetter.htm

If it does not work, let me know.