users@jsonb-spec.java.net

[jsonb-spec users] [jsr367-experts] Re: [2-DefaultMapping] Proposal

From: Przemyslaw Bielicki <pbielicki_at_gmail.com>
Date: Tue, 24 Feb 2015 09:36:12 +0100

Hi,

I have few questions regarding POJO. What worries me is the need for
default constructor. I would add @JsonbType annotation similarly to
@XmlType in which we have to specify factory class and/or factory
method. For many cases default constructor is enough but as soon as
you want your objects to be managed by CDI / Spring you have a
problem.
If we supported Java 8 we could also add method with
java.util.function.Supplier<T> parameter that would be the most
elegant option IMO. Unfortunately in this JSR we are not supposed to
be aware of Java 8 :)

Another aspect is the naming of attributes. You assumed camel case
naming? E.g. private String name; will become "name" in JSON. What
about private String firstName; ? What if I don't want camel case but
underscore separator e.g. "first_name"? I think it would be nice to
let JSON-B users define their naming convention globally using
JsonbConfig and per class using annotations.

For the unmarshalling we could even add option to ignore case e.g.
"name", "NAME", "NaMe" could be equal.

For null handling I would like to have Optional<T> but it's again Java
8 and later. Anyway, I hope we will be able to add support for
Optional<T> as a plugin later on, because it would be very very
beneficial.

Cheers,
Przemyslaw

On Fri, Feb 13, 2015 at 8:26 PM, Martin Vojtek <martin.vojtek_at_oracle.com> wrote:
> Hi,
>
> I have pushed new branch default_mapping, which contains initial examples for default mapping.
>
> There are also comments, which contain information about concepts like null handling and default field access strategy.
>
> Default mapping of dates and generics handling is not part of this commit and will be addressed separately.
>
> Looking forward to your feedback.
>
> Thank you,
> Martin Vojtek