-
Notifications
You must be signed in to change notification settings - Fork 31
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
Task/4 Implement simple serialization capability #82
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The `toJson()` on `JsonOverlay` now checks whether its initial json is still current, and if so just uses that. Thus for the vast majority of applications that are read-only, serialization will be extremely fast. However, the mutation API methods now all notice when an overlay object's value has changed, and they mark their JSON value as no longer current. Then `toJson()` calls `createJson()`, whose job it is to create a new JSON structure representing the current overlay value. This is implemented for all but `ObjectOverlay`, for which preserving ordering of child structures is difficult and needs work.
These will support creating JSON from an ObjectOverlay, and will also replace the reflection-based field accessor mechanism.
This replaces the reflection-based accessors formerly implemented by `ObjectOverlay`. Path-based value retrieval is now implemented across all JsonOverlay classes, in the form of the `find(JsonPointer)` method. This is far more powerful than the prior feature, and without the cost of reflection. ObjectOverlay extension classes must now, at construction time, provide information required by the `ObjectOverlay` implementation of this feature. The `ObjectOverlay` constructors call out to abstract method `installPropertyAccessors` to trigger this.
Required fixing some issues with PropertyAccessors, and chaging Link.href to Link.operationRef in the test yaml
Running codegen from scratch yielded a SchemaImpl java source that was missing a required import of JsonPointer. Now that's fixed.
The `createJson` method now works for all overlay types and creates correct JSON for each. However, it blindly follows references and so does not yield the same result as a `toJson` method when the in the presence of references, and when the parsed model has not been modified. Following references should be an option, and without it, `createJson` and `toJson` should yield equivalent trees.
Also modified JsonLoader to use the trimmed model text only to guess whether it's JSON or YAML, but then actually parse the untrimmed text. Using the trimmed text had unintended potential effect of dropping a line terminator in a final block-literal string in a YAML file.
This shouldn't have changed anything, but a reformatted version of SecurityRequirementImpl had been mistakenly checked in. This is now as produced by code generator, to avoid future confusion.
Boolean option enables link following in both toJson and createJson methods. Locally available JSON object in a JsonOverlay object should be one that includes references, so toJson only updates locally stored JSON if followRefs is false.
Also changed getJson method to protected, as it shouldn't be part of the public API
This was referenced Sep 25, 2017
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All objects in a model (including the model itself) now support
toJson()
andtoJson(boolean followRefs)
methods.These methods create a
JsonNode
structure reflecting the current model. Behind the scenes, the last computed (or parsed) JSON is cached in each overlay object, and the mutation API methods mark affected overlay objects as being out-of-date. In that case,toJson
will refresh the cached JSON by recomputing it.Unlike the general API, the cached JSON always reflects references, rather than invisibly following them. However, the
toJson(true)
will construct a JSON structure by following references. There is currently no protection against recursive references, so stack overflow will result in that case. (Actually that will happen during parsing until #64 is addressed.)Note that this serializer does not currently preserve as-parsed ordering of object properties; map and list ordering is preserved.
A more advanced, separate serializer is anticipated, with various options related to reference following and related behaviors.