Comments (5)
@XIAYM-gh Thanks for submitting this issue. While the spec does not seem to disallow duplicate object keys, I am not sure how it would work in JSON-Java. For example, what should JSONObject do with a duplicate key, since it cannot be stored as-is?
If implemented, it will need to be opt-in using JSONParserConfiguration to capture the option. That class is implemented in #805, which is stalled at the moment.
Suggest that you try forking the project, implementing non-unique key support in a way that makes sense to you, and get an idea of how it might affect the rest of the library.
from json-java.
Thanks for replying, I will take a look at it.
but because I'm a senior high student in China mainland, it's hard for me to do that until the 30th day of this month
sorry
from json-java.
So, I've implemented 4 handling methods in my PR and here are them:
THROW_EXCEPTION
, it's the original way to handle duplicate keysOVERWRITE
andIGNORE
, they are quite useful actuallyMERGE_INTO_ARRAY
, this is the default method that the json-lib use, and it may be useful sometimes for somebody
What do you think about them?
from json-java.
@XIAYM-gh Thanks for posting.
For context, here is what rfc-8259 says about objects:
`An object structure is represented as a pair of curly brackets
surrounding zero or more name/value pairs (or members). A name is a
string. A single colon comes after each name, separating the name
from the value. A single comma separates a value from a following
name. The names within an object SHOULD be unique.
object = begin-object [ member *( value-separator member ) ]
end-object
member = string name-separator value
An object whose names are all unique is interoperable in the sense
that all software implementations receiving that object will agree on
the name-value mappings. When the names within an object are not
unique, the behavior of software that receives such an object is
unpredictable. Many implementations report the last name/value pair
only. Other implementations report an error or fail to parse the
object, and some implementations report all of the name/value pairs,
including duplicates.
JSON parsing libraries have been observed to differ as to whether or
not they make the ordering of object members visible to calling
software. Implementations whose behavior does not depend on member
ordering will be interoperable in the sense that they will not be
affected by these differences.`
The JSON-Java object representation is fixed as an unordered map with unique keys in this
implementation. That will not be changed, so ignore
is not an option.
If someone has a reasonable use case for merge_into_array
, feel free to
post a comment, otherwise it should probably be omitted as well.
That leaves throw_exception
(the default behavior), and overwrite
.
No objection if you want to try adding overwrite
as an opt-in behavior in JSONParserConfiguration
or ParserConfiguration
. It is probably not necessary to use JsonDuplicateKeyStrategy
.
from json-java.
Oh thanks, I will do it as soon as possible
from json-java.
Related Issues (20)
- JSONObject.toString does not use an Enum's `toString()` but its `name()` HOT 5
- Separate Control for Type Conversion of Numbers and Booleans in XML to JSON Conversion HOT 3
- Allow type widening (eg integer to string) HOT 1
- Cleanup and merge tests HOT 1
- Performance improvement for POJO conversion into JSONObject HOT 1
- Migrating to Junit 5 HOT 7
- A0p HOT 1
- Externalize JSON Test Files
- Information is lost when converting hexadecimal value from xml to json. HOT 6
- JavaDoc warnings are present HOT 4
- JavaDoc warnings in Java 21 HOT 2
- Enhancement: Replace assetTrue with assetEquals in tests HOT 2
- Enhancement: Improve toString performance HOT 2
- Suggestion: Code Coverage Badge HOT 1
- Minor: "latest release" points not to the newest release HOT 2
- Problem with optLong, getLong when parsing JSONObject and XML HOT 3
- JSONArray converting incorrect input string to array HOT 7
- Automatically update Javadoc with GitHub Actions HOT 1
- Update Wiki: Where are the unit tests HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-java.