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

Use LinkedHashMap for additional properties, so the original ordering in the JSON is preserved #1397

Merged

Conversation

jdimeo
Copy link
Contributor

@jdimeo jdimeo commented Apr 30, 2022

Original GitHub issue:

It's quite annoying that additionalProperties values lose their initial array order when json is parsed.
Since I use the same schema classes to generate json after tweaking, I can't sort them too.
I guess it will be easy to add an option to generate LinkedHashMap instead of HashMap for additionalProperties field.

@joelittlejohn joelittlejohn changed the title #1273 Use LinkedHashMap for additional properties so the original ordering in the JSON is preserved Use LinkedHashMap for additional properties, so the original ordering in the JSON is preserved May 1, 2022
@joelittlejohn joelittlejohn added this to the 1.1.2 milestone May 1, 2022
@joelittlejohn joelittlejohn merged commit f0b606e into joelittlejohn:master May 3, 2022
@rohanKanojia
Copy link

@jdimeo @joelittlejohn : Hello, Is there any way to revert to the old java.util.HashMap type for additionalProperties? We're trying to migrate to v1.2.1 and facing this issue.

@joelittlejohn
Copy link
Owner

@rohanKanojia what's the issue you're facing?

@rohanKanojia
Copy link

@joelittlejohn : Sorry for the wording, it's not really an issue but a change. I'm wondering if any KubernetesClient user could complain about this.

We use JsonSchema2Pojo to generate POJOs for Kubernetes objects in https://github.com/fabric8io/kubernetes-client

After the bump to 1.2.1 in fabric8io/kubernetes-client#4895 , we have all the generated POJOs modified with additionalProperties type update. I just wanted to check if there is some way to avoid this.

@jdimeo
Copy link
Contributor Author

jdimeo commented Jun 28, 2023

I think this is a welcome change for any users. It's just an implementation class change, not an interface/contract change, and the only reason someone wouldn't want this is if their map was giant so the extra bookkeeping of the linked list incurred too much memory overhead, which for additionalProperties use cases is very unlikely/unusual. Is that edge case worth another configuration setting? I didn't think so.

@rohanKanojia
Copy link

@jdimeo : Thanks for the clarification! I'll push for this change in fabric8 k8s client.

@logeshwaranRR
Copy link

Original GitHub issue:

It's quite annoying that additionalProperties values lose their initial array order when json is parsed.
Since I use the same schema classes to generate json after tweaking, I can't sort them too.
I guess it will be easy to add an option to generate LinkedHashMap instead of HashMap for additionalProperties field.

@jdimeo is there any way to use java.util.HashSet or java.util.TreeSet in Json schema? because the user would want to use any collection type they want

@jdimeo
Copy link
Contributor Author

jdimeo commented Jan 20, 2024

Not for additionalProperties no, because it's specifically a map of keys to values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants