-
Notifications
You must be signed in to change notification settings - Fork 471
issue #288: (Approach #2) Allow links on a particular rel to be displayed as an array even if there is only one link #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Allows links under a single rel to be represented as a multiple (i.e., serialized to an array) even if there is only one.
What is "the other one" you're referring to. |
The other one had the setting on the I did try to do it via I like the approach you suggested with the configuration options. I'm assuming that we would pass in the class of the resource and the rels that need to be forced into an array representation? Perhaps in some sort of map? I'll look into that option a little bit more. I think there would still be the problem of lacking context inside the |
@olivergierke Do you know of a way how we can keep track of the resource that is also being serialized while its links are being serialized? |
@olivergierke I've been looking into this to try and figure out how I can convey information to the list serializer regarding the owning resource. Do you have a suggestion as to how this can be accomplished? This is why I added the |
@olivergierke Another question (sorry for so many!). After thinking about this a bit more, I think I will take an approach where we always force certain rels to be serialized into an array. That is, instead of doing it based on the resource it belongs to, we do it regardless. So wherever the rel appears, it will always be serialized into a list of links. From an API-design perspective, I think this is what I was going for anyway (with regard to consistency). My question is regarding configuration. Would you prefer that this be configured using an annotation (kind of like how we are doing it right now with |
Closing this pull request. Please see #295. |
…ng options. We now expose HalConfiguration to be defined as Spring bean in user configuration to control certain aspects of the HAL rendering. Initially we allow to control whether links shall always be rendered as collection. If no user-provided bean is available, we register a default instance. Original pull request: #295 Related issues: #291
Moved RenderSingleLinks enum into HalConfiguration. Simplified HalConfiguration setup by moving the default into the class. The lookup of a user-provided HalConfiguration is now handled on the bean name level to avoid premature initialization of a potentially defined bean. Formatting. Original pull request: #295 Related issues: #291
Allows links under a single rel to be represented as a multiple (i.e., serialized to an array) even if there is only one.
This approach is a little better than the other one. Here, I created a new annotation that you can attach to a resource class. This annotation will contain a list of
rel
s that will always be serialized as multiple links (i.e., in a JSON array) regardless of cardinality.I did have to add a propertly to the
Link
class, which is just the class of the owning resource. The setter is package-private and so no one else can mess with it. The value of the field is set automatically when links are added.I have also added a test for this case.