users@jsonb-spec.java.net

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

From: Romain MB <rmannibucau_at_tomitribe.com>
Date: Wed, 29 Apr 2015 18:09:38 +0200

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