Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.5
-
Component/s: None
-
Labels:None
Description
> Hello.
> Is there way to configure or customize ObjectMapper in such way that if
> Field or Method does not have JsonView it will not be serialized when View
> class is specified in the setSerializationView method.
> Right now (as default), even if I pass View to setSerializationView method,
> all fields and methods that don't have any view annotated with them will be
> serialized anyway. I would expect that if I specify View then only
> fields/methods annotated by that view will be serialized.
> It makes my life hard since if I have lots of objects that can embed each
> other. As solution, I need to go and create fake View (that will not be used
> anywhere) just to exclude those fields. I can't used JsonExclude since
> sometime I will Jsonize object without any view at all.
Currently, no.
It would be quite easy to add a setting to do to either:
(a) Reverse default of "visible unless otherwise stated" to "invisible
unless ..." or
(b) Allow setting of default view to use for non-annotated fields
(current settings are equivalent to having JsonView defined as
Object.class)
I assume (a) would be enough, but (b) would cover basic use case and
allow for other uses as well.
Can you fire a Jira issue for such a feature? Right now I am busy
working on polymorphic type handling for 1.5 (~60% done), but others
might be able to help with this feature on short term.
It should be very easy to add, just add a new
SerializationConfig.Feature.VIEW_INCLUDE_NON_ANNOTATED (or whatever),
add a check in BeanSerializer (or BeanPropertyWriter) for the feature.
+ Tatu +
I think I just may be able to squeeze this in 1.5 release: only have one major thing to work on (ability to define root type to use,
JACKSON-195), and this seems like a low-hanging fruit. So with these, and good testing for PTH, can finalize 1.5.JACKSON-195), and this seems like a low-hanging fruit. So with these, and good testing for PTH, can finalize 1.5.