Skip to content
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

Add a way to pass std and format-specific parser/generator flags during parser/generation construction #1058

Closed
cowtowncoder opened this issue Dec 28, 2015 · 3 comments
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x
Milestone

Comments

@cowtowncoder
Copy link
Member

(note: functionality is cross-cutting between databind and jackson-core, but I'll file main issue here)

With Jackson 2.6, it is possible to specify dynamically changeable "standard" parser/generator features (JsonParser.Feature, JsonGenerator.Faeture), by using ObjectReader / ObjectWriter methods.
Jackson 2.7 adds similar functionality to pass format-specific features for other data formats.

But one problem in both cases is that the way overrides are passed only comes after construction of parser / generator instances. This works for most features, but not all, as some constructors (or, parser bootstrappers) must use information they get from factory; and as a result, a subset of features can not be passed dynamically.

While it would be technically possible to rewrite parser, generators to have sort of delayed initialization for features involved, that would lead to more complex state, error-prone checks.
So instead it would seem better to be able to pass feature flags to the constructors.
Aside from explicitly passing flags, a better (not perfect but better) encapsulation could be to use existing IOContext for passing this information.

But even with IOContext, there is the question of how overrides would be passed to JsonFactory and sub-classes. The long and short of it is that this must be done by adding new factory methods for construction. This is unfortunate, but I don't see a way around that.

One remaining question there is how methods should be augmented. One possibility would be to pass two int flag sets; but this seems fragile, and bit confusing in some cases (when passing byte[] or char[] buffers with offsets). It is also non-extensible.
Adding a new simple configuration container interface type is probably a lesser evil -- while we do want to minimize additions, one more interface, implemented by existing context objects (SerializerProvider, DeserializationContext), probably would work quite well. Note that while abstract class would usually be a better choice, here existing inheritance hierachy prevents this approach.

@cowtowncoder cowtowncoder changed the title Add a way to pass std and format-specific parser/generator flags during parser/generation construction (2.8) Add a way to pass std and format-specific parser/generator flags during parser/generation construction Jan 9, 2016
@cowtowncoder
Copy link
Member Author

Actually, use of IOContext may be unnecessary, if (when) factory methods need to be modified anyway, and a new interface type added. Still, will need to wait 2.8 at this point.

Also realized that earlier work with overrideFormatFeatures will probably get obsoleted rather fast.

@cowtowncoder
Copy link
Member Author

Still trying to figure out whether to work in those for 2.8, or wait until 2.9. Main concern is backwards compatibility: change will inevitably make 2.8 less compatible with 2.7. On the other hand it is not trivially easy to do incremental additions either to perhaps add preparations in 2.8, but complete in 2.9.

@cowtowncoder cowtowncoder changed the title (2.8) Add a way to pass std and format-specific parser/generator flags during parser/generation construction (2.9) Add a way to pass std and format-specific parser/generator flags during parser/generation construction Apr 22, 2016
@cowtowncoder cowtowncoder changed the title (2.9) Add a way to pass std and format-specific parser/generator flags during parser/generation construction Add a way to pass std and format-specific parser/generator flags during parser/generation construction Sep 30, 2016
@cowtowncoder cowtowncoder added 3.x Issues to be only tackled for Jackson 3.x, not 2.x and removed 2.9 labels Mar 28, 2017
@cowtowncoder cowtowncoder added this to the 3.0.0 milestone Oct 9, 2017
@cowtowncoder
Copy link
Member Author

Implemented this via new ObjectReadContext / ObjectWriteContext added in jackson-core: factory will get changes to format flags and pass fully resolved set to parsers, generators being constructed. This allows for timely setting during construction without requiring postponing use or such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x
Projects
None yet
Development

No branches or pull requests

1 participant