Comments (12)
There is only one reason: because I programmed it this way ;) I guess the code can be changed to preserve key ordering. I did it mostly out of habit, and because syntax checking/keyword validation also did it that way (with the notable exception of format
).
HOWEVER: JSON itself has no notion of order. But Jackson uses a LinkedHashMap internally to store object members, which is why the default is indeed to respect the order of appearance.
from json-schema-validator.
Is there a way that we can specify an ordering? Perhaps "Alphabetical" or "Preserved" can be options to the walker.
from json-schema-validator.
It can be done but it will require reimplementation of some pointer collectors and of one part of doWalk()
in SchemaWalker
. Namely, collection of all pointers for properties
, patternProperties
, dependencies
will need modifying, along with this part of the code:
Ideally though, the ordering should be when generating the JSON tree itself -- again, that is a plan for future version of Jackson. Right now it is not easy to do :/
The problem is that the code needs factorization. I think a pair of WalkingConfiguration{,Builder}
are in order to satisfy this, paired with a SchemaWalkingFactory
. Comments?
from json-schema-validator.
I think a Walking(Walker?)Configuration would be a good thing, here are some things that could be considered for the configuration.
- order in which you walk the properties (alphabetical, reverse alphabetical, key ordering, reverse key ordering)
- onWalk call on the "old tree" or the "new tree", I noticed that on walk is currently only called on the old tree, and then the new tree's properties. (This was found on the resolving schema walker)
from json-schema-validator.
Hmm, not sure whether there is an interest to walk either the old or the new tree?
from json-schema-validator.
There is an important note here: when encountering a JSON Reference, other members of the object should be ignored.
Therefore, if, in ResolvingSchemaWalker
, both the old and new tree were walked, this would be a violation of the JSON Reference spec. Not sure we want to go there.
Also, onWalk()
should really only be called on the resolved tree. This is a question of inverting these two lines here:
I also wonder whether the onTreeChange()
(which is raised by the call to resolveTree()
line 127) event is actually any useful. I cannot remind why I did it this way, except maybe because I figured out one would may need information from the old tree before switching trees? I don't know. But retrospectively it doesn't sound like a good idea.
from json-schema-validator.
OK, I think the listener interface needs to change for -core 1.2 (it's too late for 1.0). It also means json-schema-validator will jump to 2.2, since I have other changes planned in the developer API which are incompatible with 2.0.
The events I plan to listen so far are, in order:
onEnter(JsonPointer ptr)
: relative push into the tree;onTreeChange(SchemaTree oldTree, SchemaTree newTree)
: tree has changed due to ref resolving;onWalk(SchemaTree tree)
: entering a tree;onExit()
: pendant ofonEnter()
.
This simplifies listener implementations quite a lot. I still am uneasy as to whether a tree change should be triggered at all. But it doesn't hurt.
Comments?
from json-schema-validator.
From what I understand from these changes, if the schema contains a reference, then the reference will be resolved and then onWalk will be called on the "new tree".
The result of this is that onWalk should never return a tree that has a $ref in it unless it is a dangling reference.
from json-schema-validator.
From what I understand from these changes, if the schema contains a reference, then the reference will be resolved and then onWalk will be called on the "new tree".
Yes, that's it.
The result of this is that onWalk should never return a tree that has a $ref in it unless it is a dangling reference.
Not only dangling. ResolvingSchemaWalker
also throws an exception if resolving results in a tree which is either a child or a parent of the tree before resolution. A child because it makes potential subschemas ignored, a parent because it would lead to infinite expansion.
from json-schema-validator.
This sounds reasonable to me and should make my listener code much easier. Thanks!
from json-schema-validator.
OK, some updates. -core 1.1.1 is out but still not there yet. In this version I have modified the listener events so as to reflect the events mentioned above (note that you also .onEnter()
the initial tree, that is, the JSON Pointer at that point will be empty).
I have not done the configuration aspect yet. I have some difficulties with how to do it properly, since I'd like to somewhat have a registry of known keywords. One intent is to log more information when walking:
- keywords which are plainly unknown (as warnings);
- keywords which are known, but not entered (as info).
All in all, still some work to do...
from json-schema-validator.
Closing this one. Tree walking will be in 3.0, it cannot go seamlessly in 2.1.x and 2.2. Though the base of it will certainly be in jackson-coreutils.
from json-schema-validator.
Related Issues (20)
- Failed validation for no apparent reason?
- Getting java.util.concurrent.ExecutionException while validating
- Error when validating Json against a schema defining oneOf
- Are we planning on supporting draft-07 HOT 1
- Example code on README.md please plus links to examples in src
- Migrate from joda-time to java 8 time API HOT 2
- Improcess error hanling in getJsonSchema - never squash exceptions
- Android app crashes because schema (v4) cannot be found at runtime HOT 2
- Getting NPE when passing null to validate method.
- Has the functionality of the ResolvingSchemaWalker been replaced in more recent versions?
- Conflicting Transitive Dependency Versions for Guava and Jsr305
- Where is pom.xml ? I want to import this library to my local and customize it
- Not compatible with GraalVM
- NoSuchFieldError on signing
- When JSONObject contains JSONArray, JSONArray's object can not be validated
- draftv4/schema is different between json-schema-validator 2.2.14 and json-schema-core 1.2.14 HOT 2
- release new version HOT 2
- How can we get Error Message with the error path appended?
- Obtain JUST the message from a ValidationMessage?
- BUG: ECMA262 valid pattern throws an exception
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-schema-validator.