I actually like applying @JsonbTransient as class level. But, there may be
some circumstances that users may want to serialize fields that its class
has @JsonbTransient.
For the Dmitry's example;
class A {
String aField;
@JsonbTransient(transient=false) // Attention
B b;
}
@JsonbTransient
class B {
String bField;
}
@JsonbTransient annotation may have a transient property that is
default=true , and users may change this behaviour by setting the transient
property like above.
What do you all think?
2016-01-13 15:47 GMT+02:00 Romain Manni-Bucau <rmannibucau_at_gmail.com>:
> Hi Dmitry,
>
> +1 to remove @JsonbTransient from class level
>
> not sure what the inlining can bring compared to adapters too so +1 to
> just remove it
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> | Blog
> <http://rmannibucau.wordpress.com> | Github
> <https://github.com/rmannibucau> | LinkedIn
> <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com>
>
> 2016-01-13 14:41 GMT+01:00 <dmitry.kornilov_at_oracle.com>:
>
>> 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
>
>
>
--
Rahman USTA
Istanbul JUG
https://github.com/rahmanusta <http://www.kodcu.com/>