Closed xedo closed 9 years ago
@JsonView
does specify view needed, IF view-specific handling is specified. By default if no view is specified, no view-based filtering occurs. So if I understand your usage correctly (you are not specifying field to use via ObjectWriter
), behaviour sounds correct
Yes, I'm specifying a View. I give you a scenario:
class Views {
public static interface PublicView {}
public static interface PrivateView {}
}
class Foo {
private String aaa;
@Transient
private String bbb;
@Transient
@JsonView(PublicView.class)
private String ccc;
@JsonView(PrivateView.class)
private String ddd;
}
What I get:
writer without specify view: {aaa:"xxx", ccc:"xxx", ddd:"xxx"}
writer with PublicView: {aaa:"xxx", ccc:"xxx"}
writer with PrivateView: {aaa:"xxx", ccc:"xxx", ddd:"xxx"}
What I spected:
writer without specify view: {aaa:"xxx", ccc:"xxx", ddd:"xxx"}
writer with PublicView: {aaa:"xxx", ccc:"xxx"}
writer with PrivateView: {aaa:"xxx", ddd:"xxx"}
That would be wrong indeed. Is this with Jackson 2.6, or an earlier version?
Just noticed that this @Transient
comes from persistence. So it is not supported by core annotations or databind, but is supported by jackson-datatype-hibernate
(https://github.com/FasterXML/jackson-datatype-hibernate/). Are you using that? I assume this is the case, and will try to repeat it with that.
If that succeeds, I'll move this issue over there, since annotations package only defines annotations and does not implement handling (databind does, mostly, but other modules add some bits and pieces too).
I can not reproduce this issue with jackson-datatype-hibernate
. A full test case is needed at this point.
I have jackson-databind:2.6.2
and jackson-datatype-hibernate4:2.6.2
I tried also with 2.6.0 and 2.4.4, but @Transient
is from javax.persistence.Transient
Test is unfortunately not stand-alone (nor verify expected behavior).
Since the problem (if any) is with hibernate module, I'll close issue here, and if you want, you can re-open at https://github.com/FasterXML/jackson-datatype-hibernate/ with a reproducible test case.
If there is a field annotated with
@Transient
(javax.persistence.Transient) it's ignored, but if I force to show it for instance with@JsonView(Foo.class)
it is always serialized, doesn't matter if I use theBoo.class
orOther.class
view. always show it