FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

@JsonView in conflict with @Transient #70

Closed xedo closed 9 years ago

xedo commented 9 years ago

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 the Boo.class or Other.class view. always show it

cowtowncoder commented 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

xedo commented 9 years ago

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"}

cowtowncoder commented 9 years ago

That would be wrong indeed. Is this with Jackson 2.6, or an earlier version?

cowtowncoder commented 9 years ago

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).

cowtowncoder commented 9 years ago

I can not reproduce this issue with jackson-datatype-hibernate. A full test case is needed at this point.

xedo commented 9 years ago

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

xedo commented 9 years ago

https://gist.github.com/xedo/4fa89389d148af43bd20

cowtowncoder commented 9 years ago

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.