Comments (11)
I built my own parser (I'm not wrapping anything) and thought I'd code it to a well-known Java spec because I like it when things are compatible; I found javax.json
. I like to implement specs, so you could say I did this for sport, but I've been going down a JSON rabbit hole. I've also implemented a JSON Schema validator too (it's called "Snow"; you'll soon find a PR in your inbox for this: https://github.com/leadpony/json-schema-conformance-test).
It all started when I was tasked with doing some RDM standards work (DMX related; lighting control and such) related to JSON schemas (rabbit hole # 1). Because no Java implementation yet implemented Draft 2019-09, I wrote one (rabbit hole # 2). Then, I went down another rabbit hole with how to effectively do proper errors and annotations such that they're not only clear, but organized well and only giving information instead of too much when there's just simple errors in a schema instance (rabbit hole # 3). I needed a break from that, remembered that I like writing manual DFA-based parsers (deterministic finite automaton), so I wrote a DFA (in truth a PDA (pushdown automaton) because it kind of needs a stack) for all the character transition states in JSON (actually, I implemented complete JSON5 support) thinking it would be as fast as possible (basically one table lookup per character read, plus another table lookup for an associated action, plus a little additional logic) (rabbit hole # 4). As I said, I like standards and compatible interfaces, so I completed a javax.json
layer for that (rabbit hole # 5). Sadly, lo and behold, GSON is still about 30% faster than mine when building objects 🤦 (mine is still very fast when just using the parser for events and not building an object tree, thankfully). I like completeness and I couldn't just leave it (GSON is faster when building the object tree, so I'm sure Jackson is too), so I completed my javax.json
layer by validating against all these tests, and here we are.
So, in summary: an attempt at a faster JSON parser, and "completeness".
from jsonp-test-suite.
@ssilverman
Thank you for reporting.
I will check them this weekend.
Are you implementing a new JSON-P compliant parser/generator?
from jsonp-test-suite.
Yes. I’ve also got a new validator and was glad to have found yours too a while back.
from jsonp-test-suite.
@ssilverman
Now I remember why I marked these cases as valid.
The purpose of this test suite is to test implementations of JSR 374 (JSON Processing) API,
which is now superseded by Jakarta JSON Processing API.
The JSON-P specification tells us that JSON Pointer in JSON-P should conform to
RFC 6901. However the RFC does not define how applications handle
such illegal tildes found in JSON Pointer, as below.
This specification does not define how errors are handled. An
application of JSON Pointer SHOULD specify the impact and handling of
each type of error.
For example, some applications might stop pointer processing upon an
error, while others may attempt to recover from missing values by
inserting default ones.
Therefore we should respect of the behavior of the Reference Implementation.
I believe the Reference Implementation ignores such syntax error and treats the tildes as normal character.
You are almost correct. I once implemented my parser to throw exceptions in such cases, but I changed it in order to conform to the Reference Implementation.
from jsonp-test-suite.
@ssilverman
If you really think JsonException
s should be thrown in these cases (I agree with you), I recommend that you draw an issue in eclipse-ee4j/jsonp.
from jsonp-test-suite.
I hear you on the point about the tests not being to test JSON nor to test the JSON-P API, it's to test the implementation of the JSON-P API. However, what happens if the implementation disagrees with its own documentation? JSON-P specifically states, in JsonProvider.createPointer
:
@throws JsonException if {@code jsonPointer} is not a valid JSON Pointer
It also states in RFC 6901 (https://www.rfc-editor.org/rfc/rfc6901.html#section-3)
It is an error condition if a JSON Pointer value does not conform to this syntax
While I agree that the RFC leaves it up to the application to handle errors, the API itself states that a JsonException
is thrown for invalid JSON Pointers. I think we can agree that "/a~2b" is not a valid JSON Pointer, per the Section 3 statement above.
So back to the first question in this post: What happens if the implementation disagrees with its own documentation? In this case the JSON-P API itself stating an exception should be thrown?
from jsonp-test-suite.
@ssilverman
Personally I agree with you.
The Reference Implementation throws an exception if a given JSON Pointer does not start with a slash. So I feel it is natural that the implementation throws an exception when it detects an illegal tilde in the JSON Pointer. I prefer such strict error checking.
But I cannot say this is a bug with 100% confidence. Apache Johnzon also does not throw an exception in this case. So I judged these test cases are valid and I modified Joy (my own implementation) in order to be compatible with other implementations.
If you are sure that this is a bug in the Reference Implementation, I recommend you consult this problem with JSON-P team.
from jsonp-test-suite.
@ssilverman
Are you developing JSON-P implementation by wrapping other JSON library, such as Jackson? Could you tell me your purpose for building yet another implementation?
from jsonp-test-suite.
@ssilverman
If you really love to implement faster software, try this benchmark.
https://github.com/leadpony/jsonp-benchmark
Your implementation is faster than the Reference Implementation?
from jsonp-test-suite.
<sigh> My implementation looks like it's 4x ops/s slower than the reference implementation. I must be doing something that's not very JIT friendly.
from jsonp-test-suite.
@ssilverman
I posted an issue in eclipse-ee4j/jsonp#266 for this problem.
from jsonp-test-suite.
Related Issues (12)
- Hex escapes should allow lower- or upper-case letters A-F HOT 14
- JsonExclusiveBadTerminationTestCase and EOF behaviour, expect exception? HOT 2
- The JsonPointer tests should expect the target to be modified HOT 3
- Two possible outputs for Double?
- getConfigInUseShouldNotContainUnknownProperty checks that config properties are removed, but shouldn't HOT 1
- String comparisons should normalize to ASCII HOT 10
- Change object output comparisons to be order-insensitive HOT 3
- G_CLEF string should escape the slashes HOT 2
- thrown.getMessage() should first check if thrown is null HOT 2
- I wish the failing tests used zero-based indexes HOT 1
- Empty JSON should cause an exception, according to the grammar 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 jsonp-test-suite.