Conversation
… and objectIdGenerators
| } | ||
| } | ||
|
|
||
| private SerializationContext getContext(SerializationContext context) { |
There was a problem hiding this comment.
Ugh. No, this adds way too much per-property write overhead -- must NOT be done on per-call basis. That is, things need to be pre-processed when constructing/initializing BeanPropertyWriters; especially annotation introspection.
Also, even then, should not be constructing new SerializationConfigs or -Contexts on critical path -- just overriding active view (_activeView, needs to change to non-final) in SerializationContext before, resetting after.
Might be possible to wrap BeanPropertyWriter to do that... ?
| * @return view (represented by class) that the property will be processed with; | ||
| * if null, processing will use the current view if any | ||
| */ | ||
| public Class<?> findApplyView(MapperConfig<?> config, Annotated a) { return null; } |
There was a problem hiding this comment.
Should the translation of "no view" be handled here?
(if so, marker effectively means "no override", same as no annotation -- except that allows for mix-ins and sub-classes to override and disable @JsonApplyView of target/base class).
|
@cowtowncoder thanks for supporting and helping me. You suggested the implementation shall go another direction with a caching of BeanWriterProperty and not cloning SerializationContext/SerializationConfig although it always check first if active view has changed or not and avoid unnecessary cloning (minimal performance impact?). Shall I attempt to find out where else we can do that, or do you have something specific in mind? |
…PropertyWriter)
|
@cowtowncoder in the meanwhile I reworked the handling in BeanWriterProperty to read the annotation just once. Maybe it's enough so, as the SerializationContext creation happens only when needed and is ultimately just a copy by reference of the properties. If you still wish to make the activeView accessible, save it before and restore it after the property it should be quite easy as well. But then you possibly have an activeView not matching its config... |
|
@cowtowncoder would you prefer another cleaner push request to be able to merge it easily? |
|
@cowtowncoder is this implementation fine enough or would you prefer to mutate the context instead. |
|
Ok, sorry, so no, not good as-is -- I don't think new Instead, active view in needs to be changed mutable. Method could then be added, something like which would switch view around call. As to this or new PR, no Strong opinion, either way fine with me. During PR could also temporarily add new annotation in databind package to make code compile & CI run. |
| public Class<?> findApplyView(MapperConfig<?> config, Annotated a) | ||
| { | ||
| JsonApplyView ann = _findAnnotation(a, JsonApplyView.class); | ||
| return (ann == null) ? null : ann.value(); |
There was a problem hiding this comment.
I think this should translate JsonApplyView.NONE.class into null so callers need do the translation or know about special casing.
There was a problem hiding this comment.
Don't we need to differentiate between
- JsonApplyView.NONE.class (for this property / serialization we don't want to apply any view aka setActiveView to null) and
- NULL (for this property / seriailzation we don't want to change anything to the current activeView) and process views as until now in Jackson
-> I think we need to document this NONE class but cannot totally hide it. It is also a special use case since the normal case will be to replace with another view and not suppress the current one.
There was a problem hiding this comment.
Hmmmh. If there is use case of forcing Active View to be set to null, yes, a placeholder needed I suppose.
So documenting this makes sense, then, and letting NONE.class be exposed.
|
@cowtowncoder I managed to revert the cloning of Context and Config and just modify the activeView in BeanPropertyWriter. Can you review my change? And possibly move forward with this PR? Thanks |
| protected final Class<?>[] _includeInViews; | ||
|
|
||
| /** | ||
| * Alternate set of property writers used when applyView is |
There was a problem hiding this comment.
Yes, I suggest the following:
/**
* View to apply for this property when applyView is available for the Bean.
*
* @SInCE 3.2
*/
|
|
||
| Class<?> currentActiveView = ctxt.getActiveView(); | ||
| try { | ||
| ctxt.setActiveView(getAppliedView(ctxt)); |
There was a problem hiding this comment.
This now adds overhead for every write call on hot path.
Not good. Should check if _applyView is null, if so, fast patch with no changes; if not null, then handle active view.
There was a problem hiding this comment.
I did it as asked. Please review again
|
@cowtowncoder here the corrections. |
|
@cowtowncoder did you get the cla? And does the change suits you? Thks |
|
Will try to get annotations PR sorted today, first, then get back here. |
As discussed, here a Draft PR.