users@jsonb-spec.java.net

[jsonb-spec users] [jsr367-experts] JsonbTransient

From: <dmitry.kornilov_at_oracle.com>
Date: Wed, 13 Jan 2016 13:41:14 +0000 (UTC)

Hi experts,

I have a question regarding @JsonbTransient annotation, declared on
types. The behaviour as it described in the spec is unclear. The spec
says:

"When placed on a class, indicates that the class shouldn’t be mapped
to JSON by itself. Properties on such class will be mapped to JSON
along with its derived classes, as if the class is inlined."

Here is some a sample illustrating it:

class A {
    String aField;
    B b;
}

@JsonbTransient
class B {
    String bField;
}

jsonb.toJson(A) -> {"aField":"someValue", "bField":"someValue"}

If it's a desired behaviour I am not sure that it's a good idea to use
"transient" keyword for inlining. Transient means "not serializable".
So transient on a type would mean that this type is not serializable at
all. The result of serializing the sample above will be:

jsonb.toJson(A) -> {"aField":"someValue"}

It's the same as putting @JsonbTransient on A.b field. I personally
don't see it as a common use case.

If we need inlining functionality maybe a better idea is to introduce
something like @JsonbInline and restict usage of @JsonbTransient to
fields only.

What do you think?

Thanks,
Dmitry