Ordered output/file writing of JSONObjects (may be repeated, nevertheless please read carefully ...)
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 25/100
Direção de pesquisa
Review the linked comment summary and JSONObject's mentioned operations, including put(), accumulate(), populate(), remove(), keys(), keySet(), and entrySet(). Confirm with maintainers which ordering approach is accepted before defining tests for ordered output and unchanged default behavior; completion depends on an agreed design, implementation, and verification of compatibility.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
A complete summary of the main issues of the comments can be found here.
In one of my repositories I am going to save the simulation state (lots of data) in a JSON file, which is shorter and can be easier changed/debugged than XML (which I used a lot in past projects). To do this in a realistic way, there is a need of ordering (similar to XML).
First of all: I had a deep dive into the code, made a fork (for my own); and yes, I read the FAQ and other files, especially "Will ordering ever be allowed ...", and I know the (IMHO unfortunate) spec "unordered" ;-)
In any case, I will use JSON-java. It suits the needs close to perfect, pretty printing, easy usage, functionality, light weight, etc.
Therefore, I will add ordering in the fork.
My suggestion: I can contribute the ordering to JSON-java - as far as I can understand not breaking the interfaces.
Due to the fact, that this a lot more work than doing it for my repo needs, I want to discuss the item and get possibly an ok for it (Assuming my code will please so ;-)
As far as I can see, there are several possibilities to add ordering not breaking the interfaces - if this is not rejected in general for some reasons:
-
Add a class member keyList (ArrayList) to JSONObject - which is null by default, not a big memory consumption. In a Context class (or a static variable/setter within JSONObject: let say setOrdering(true) before the user takes action) the keyList gets a small ArrayList. If the keyList or flag exists/is set, all put(), accumulate(), populate()-dependent ops will add the key(s) to that keyList - this preserves ordering, remove ops have to take care of keyList. All get(), keys(), keySet(), entrySet(), ... ops will return ordered items, cause the keys will come in an ordered way or Set from keyList. All map-dependent ops will still work in an unordered way.
AFAIK, no interface is broken, all existing code works like in the past, old output/files/Strings are still the same - e.g. a previous JSONObject.setOrdered(true) makes things ordered. Some work for me ;-) -
Extend JSONObject to let say JSONObjectOrdered, add a member keyList (ArrayList) and override most of the above methods, using the keyList to retrieve any key, entrySet etc. Possibly some private methods have to be copied (e.g. private wrap() - not a smart solution).
In that case, other classes may undergo a lot of changes like: isInstanceOf JSONObjectOrdered.
Any ordered attempt can be made by using JSONObjectOrdered instead of JSONObject to generate the JSON tree.
Default behaviour does not change, no interface is broken, but it looks a little bit unaesthetic. Anyone who wants to write ordered uses JSONObjectOrdered. Not my preferred solution for a public framework, but I may use this for my own repo if a contribution is not within the projects meaning. (Far less work for me). -
Any of your suggestions, better than above - please tell.
My 2 cents for the public, please respond.
(You may also contact me on the mail address found at the Github user openworld42)
- Linguagem predominante
- Java
- Estrelas
- 4.7k
- Forks
- 2.6k
- Merge médio
- 6d 20h
- PRs com merge (30d)
- 2
Preparar o ambiente
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de stleary/JSON-java
-
Fix before the next release
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
New JSONPointer tests neededAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
Fix before the next release
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Todas as issues de stleary/JSON-java
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
OpenAPITools/openapi-generator#25014 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
openhab/openhab-core#5847 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
apache/parquet-java#3820 ·
Mantenedores costumam responder em até 1 dia