users@jsonb-spec.java.net

[jsonb-spec users] [jsr367-experts] Re: [17-Customizing names]

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

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

> 2015-04-29 18:30 GMT+02:00 Martin Vojtek <voytoo_at_gmail.com>:
> > 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).
> >
>
> think we can do better than something called each time here. Why not
> just a Mapper? String map(Accessor)?
>
>
this is mapping from Accessor to JSON. This works in many cases (like 1:1),
but what about other cases like case insensitive special case?

If we agree that this is enough and the special case will be handled by
JsonbAdapter, that it is ok.



> > 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.
> >
>
> Makes sense but i would still add it in property and keep @Nillable
> for type and packages only.
>
>
Don't have strong opinion about this. What others think?



> > ad 3)
> >
> > Maybe it makes sense to make it more general. What about JSON Pointer?
> >
>
> can make sense but should stay simple/fluent cause it is super common
> (github/confluence/...). If you have some pseudo code we can discuss
> around I would be more than happy to dig into it.
>
>
I was thinking about similar functionality as MOXy XPath provides.

https://wiki.eclipse.org/EclipseLink/Examples/MOXy/XPath

JSON-B could support reasonable subset of JSON Pointer to map field
(JavaBean property) to given node.


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