Skip to content
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

Ordering of properties within a HAL forms template #1114

Open
smcgregor83 opened this issue Nov 4, 2019 · 3 comments
Open

Ordering of properties within a HAL forms template #1114

smcgregor83 opened this issue Nov 4, 2019 · 3 comments
Labels
in: mediatypes Media type related functionality type: enhancement

Comments

@smcgregor83
Copy link

I am playing around with the new HAL forms functionality and I have a question. It appears that properties within the affordance templates are being sorted alphabetically losing the order specified on the POJO. I presume this will be by design.

My goal is to create a client which renders dynamic forms based on the response from the API but I would want to be able to control ordering from the server. A simple workaround I can see is a prefix on the name of the field (i.e. field1_firstName, field2_lastName, field3_email).

Is there a recommended approach for doing this? Is it possible to retain the order of the properties as defined in the POJO?

@gregturn
Copy link
Contributor

gregturn commented Nov 4, 2019

While I sympathize with your desire to control the order of properties on an HTML form, it appears that the code that retrieves properties of a POJO are found in the Spring Framework (BeanUtils. getPropertyDescriptors):

private static Stream<PropertyDescriptor> getPropertyDescriptors(Class<?> type) {
return Arrays.stream(BeanUtils.getPropertyDescriptors(type))
.filter(descriptor -> !FIELDS_TO_IGNORE.contains(descriptor.getName()))
.filter(descriptor -> !descriptorToBeIgnoredByJackson(type, descriptor))
.filter(descriptor -> !toBeIgnoredByJackson(type, descriptor.getName()))
.filter(descriptor -> !readerIsNotToBeIgnoredByJackson(descriptor));
}

There is no form of sorting done inside Spring HATEOAS, so I don't see how to affect any changes.

@odrotbohm
Copy link
Member

I wonder if HalFormsConfiguration could expose API to help define the order, either through some configuration callback or an explicit ordering call ….withFieldOrderFor(Foo.class, "firstname", "lastname". Making use of the field declaration order is quite involved as it would require us to use ASM to scan the class' bytecode.

In general any kind of reflection lookup of properties does not regard any declaration orders as in the reflection API methods do not guarantee any order of the results at all.

@odrotbohm odrotbohm added in: mediatypes Media type related functionality type: enhancement labels Dec 10, 2019
@gregturn
Copy link
Contributor

With options for a “strict” mode that ONLY applies to the specified type, and perhaps an “inherited” mode that does an instanceof check?

gregturn added a commit that referenced this issue Apr 30, 2020
Register various patterns of sorting based on types.
gregturn added a commit that referenced this issue Apr 30, 2020
Register various patterns of sorting based on types.
gregturn added a commit that referenced this issue Apr 30, 2020
Register various patterns of sorting based on types.
gregturn added a commit that referenced this issue Apr 30, 2020
Register various patterns of sorting based on types.
gregturn added a commit that referenced this issue Apr 30, 2020
Register various patterns of sorting based on types.
gregturn added a commit that referenced this issue May 1, 2020
Register various patterns of sorting based on types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mediatypes Media type related functionality type: enhancement
Projects
None yet
Development

No branches or pull requests

3 participants