users@jsonb-spec.java.net

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

From: Romain MB <rmannibucau_at_tomitribe.com>
Date: Tue, 17 Mar 2015 12:12:49 +0100

+1 marshalling order is important

About set of fields we have several cases:
- using fields: we don't care much IMO
- using methods: we have to align on java to not get surprises (if a
setter uses another field/parent field)
- using constructor: all is done smoothly


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2015-03-17 11:21 GMT+01:00 Eugen Cepoi <cepoi.eugen_at_gmail.com>:
> Hum, I don't know if it is worth to make deser order customizable. The only
> use case I see where someone would want parent fields to be set first is
> when he does some ugly init. logic in setters and the order matters. And
> this use case sounds as bad code. Also this is too technical and low level
> IMO to let the user configure anything. I'd say, let him configure the order
> props are being ser. and thats all.
>
> 2015-03-17 11:11 GMT+01:00 Martin Vojtek <voytoo_at_gmail.com>:
>>
>> Hi Eugen, agree with performance issue. Let's set it in order.
>>
>> It should be customizable to allow other options.
>>
>> On Tue, Mar 17, 2015 at 10:58 AM, Eugen Cepoi <cepoi.eugen_at_gmail.com>
>> wrote:
>>>
>>> OK for 1 and 2, but I disagree with 3. It is inefficient, during deser.
>>> lets "set" them in the order they appear in the stream.
>>>
>>> 2015-03-17 10:08 GMT+01:00 Martin Vojtek <voytoo_at_gmail.com>:
>>>>
>>>> I suggest the following default for inheritance, order of fields (for
>>>> default mapping):
>>>>
>>>> 1. Fields MUST be marshalled(serialized) in lexicographical order.
>>>> 2. Fields of super class MUST be marshalled(serialized) before fields of
>>>> child class.
>>>> 3. When unmarshalling, fields of super class MUST be set before fields
>>>> of child class.
>>>>
>>>>
>>>> ad examples: I will add examples for suggested cases. In general, feel
>>>> free to
>>>> send me diff file or create some github fork to propose changes/examples
>>>> and I will incorporate it (if you don't have commit rights).
>>>>
>>>>
>>>> MartinV
>>>>
>>>> On Mon, Mar 16, 2015 at 2:03 PM, Przemyslaw Bielicki
>>>> <pbielicki_at_gmail.com> wrote:
>>>>>>
>>>>>> 1. Do we rellly want to specify ordering of POJO fields based on
>>>>>> lexicographic order of field names?
>>>>>> I think better rely on fields order of appearance in class as it done
>>>>>> in Gson.
>>>>>
>>>>>
>>>>> Eugen is completely right here. The order is nor guaranteed in runtime.
>>>>>
>>>>>>
>>>>>>
>>>>>> 2. Inheritance, order of fields. Should we specify default order of
>>>>>> fields when using inheritance? Which field set is to be first - fields of
>>>>>> subclass or fields of superclass? In gson superclass fields go first.
>>>>>
>>>>>
>>>>> Good point. As usual let's come up with a reasonable and proved default
>>>>> + @Annotation to override it for advanced users.
>>>>>
>>>>>>
>>>>>> 4. Lets add examples for POJO classes wth Collections/Arrays fields
>>>>>> (one to many relation).
>>>>>>
>>>>>
>>>>> I think you're more than welcome to commit you changes :)
>>>>>
>>>>> Cheers,
>>>>> Przemyslaw
>>>>>
>>>>>
>>>>
>>>
>>
>