jsr367-experts@jsonb-spec.java.net

[jsr367-experts] Re: [17-Customizing names]

From: Martin Vojtek <voytoo_at_gmail.com>
Date: Wed, 29 Apr 2015 18:30:14 +0200

Hi,

ad 1) interface for PropertyNamingPolicy?

I was experimenting with the idea of interface, but there is an open
question how to design API to provide support also for the reverse mapping.

For example, if I have case insensitive mapping, I need to know how to map
from JSON key to field name (in efficient way). I have removed such an
interface to see if there is a need for such customization (obviously there
is :)).

The alternative is to provide mechanism analogical to JAXBAdapter mechanism
(or general mapper for given type).

ad 2)

The difference between JsonbNillable and JsonbProperty is also in scope. It
makes sense to make JsonbNillable property to be available for Type/Package
target.

ad 3)

Maybe it makes sense to make it more general. What about JSON Pointer?

ad ProertyOrderStrategy with enum)

no problem to introduce enum. In that case I would also add
LEXICOGRAPHICAL, which is default (and slightly different than
ALPHABETICAL).

MartinV


On Wed, Apr 29, 2015 at 6:09 PM, Romain MB <rmannibucau_at_tomitribe.com>
wrote:

> Hi
>
> @JsonbProperty is good to rename a property.
>
> However I don't like much PropertyNamingPolicy being an enum. How do I
> do if I want to prefix everything with "mysuperapp_"? I would use an
> interface instead with default implementations (as constants in Jsonb
> or in a DefaultPropertyNamingPolicies enum if you want). This would
> also be consistent with PropertyOrderStrategy (why not having an enum
> with ALPHABETICAL, REFLECTION, REVERSE...)
>
> I think having nillable as an attribute of @JsonProperty is maybe better.
>
> Now the harder question. Suppose I have this json:
>
> {
> "foo": {
> "bar": "dummy"
> }
> }
>
> Can I map foo/bar to a field directly? I'm super tempted to support
> it. It means @JsonbProperty needs an array of string instead a simple
> String:
>
> public class MyBinding {
> @JsonbProperty({ "foo", "bar" })
> private String bar;
> }
>
> Side note: of course this doesn't prevent simple renaming with the
> same user API as today (speaking about the "look") thanks to
> annotations properties:
>
> public class MyBinding {
> @JsonbProperty("foo")
> private Foo _foo;
> }
>
> trying to summarize my feedback, here are the points I'd like to discuss:
>
> 1) interface for PropertyNamingPolicy?
> 2) nillable in @JsonbProperty (means value() would have an empty
> default to keep a nice API in all cases)
> 3) nested attribute support?
>
>
> Romain Manni-Bucau
> @rmannibucau
> http://www.tomitribe.com
> http://rmannibucau.wordpress.com
> https://github.com/rmannibucau
>
>
> 2015-04-29 17:36 GMT+02:00 Martin Vojtek <voytoo_at_gmail.com>:
> > Hi Experts,
> >
> > I have pushed proposal regarding Customizing names.
> >
> > Short summary:
> >
> > introduce annotation and enum with most common naming policies.
> >
> > 1. use of javax.json.bind.annotation.JsonbProperty
> > 2. using javax.json.bind.config.PropertyNamingPolicy
> >
> > JsonbProperty annotation is applicable to Field, getter or setter.
> >
> > PropertyNamingPolicy enum contains several different policies like
> IDENTITY,
> > CASE_INSENSITIVE, LOWER_CASE_WITH_UNDERSCORE ...
> >
> > Details could be found in specification and in code (api + examples).
> >
> > MartinV
> >
> >
>