The example I was thinking about is following:
interface FunctionalInterface<T> {
public T getValue();
}
Genson:
public void test() {
FunctionalInterface<String> myFunction = () -> {return "value1";};
assertEquals("{\"value\":\"value1\"}", genson.serialize(myFunction));
}
Proposed JSON-B:
FunctionalInterface<String> myFunction = () -> {return "value1";};
assertEquals("{}", jsonb.toJson(myFunction));
The difference is in handling getters when there is no field.
MartinV
On Mon, Apr 6, 2015 at 11:22 PM, Eugen Cepoi <cepoi.eugen_at_gmail.com> wrote:
>
>
> 2015-04-06 22:47 GMT+02:00 Martin Vojtek <voytoo_at_gmail.com>:
>
>> Hi,
>>
>> response inlined.
>>
>> Thanks,
>> Martin
>>
>> On Sun, Apr 5, 2015 at 5:57 PM, Oleg Tsal-Tsalko <oleg.tsalko_at_gmail.com>
>> wrote:
>>
>>> Hi guys,
>>>
>>> Feedback on generic mapping serialization examples:
>>> 1) Why there are no examples of actual usage of proposed
>>> Jsonb#toJson(Object, Type) method?
>>> I assume these examples should justify usage of this advanced method in
>>> those special/tricky cases where Jsonb#toJson(Object) method is not
>>> enough.
>>>
>>
>> Will add example:
>>
>> List<java.util.Optional<String>> expected = Arrays.asList(Optional.empty(), Optional.ofNullable("first"), Optional.of("second"));
>>
>> String json = toJson(expected, DefaultMappingGenerics.class.getField("listOfOptionalStringField").getGenericType());
>> assertEquals("[null,\"first\",\"second\"]",json);
>>
>>
>>
>>
>>> 2) Probably it was missed by me but are we going to support
>>> serialization of anonymous interfaces/classes implementations at all?
>>> As an example:
>>> myFunction = new FunctionalInterface<String>() {
>>>
>>> private String value = "initValue";
>>>
>>> @Override public String getValue() {
>>>
>>> return value;
>>>
>>> }
>>>
>>> public void setValue(String value) {
>>>
>>> this.value = value;
>>>
>>> }
>>>
>>> };
>>> assertEquals("{\"value\":\"initValue\"}", jsonb.toJson(myFunction));
>>> It doesn't look like valid scenarios to support.
>>> AFAIK, Gson lib doesn't support this...
>>>
>>
>> Don't see reason why it is not valid scenario.
>>
>> Genson supports it (with different result in some cases as proposed
>> JSON-B) :)
>>
>
> Heh looks like you had an in depth look at it :) In what situation did it
> produce different or undexpected results?
>
> I added it because the effort to support it was not so important and this
> can be of some use. But this looks like a rare use case so I am not feeling
> strongly for or against it. I don't feel so concerned by the examples as
> IMO they are just examples and its OK if they don't cover all the API
> (after all it is not the spec).
>
> About supporting deser missing properties I 100% agree with the remark but
> think it should be expressed as a config option that would make things
> clear that impl. have to support this feature (and don't really care about
> the example).
>
> I wonder if providing those examples doesn't make things more confusing
> about what is the contract that impls should respect.
>
> Eugen
>
>
>> It would be helpful to hear some opinions from others on this topic.
>>
>>
>>> 3) Expected result in bounded example doesn't look right:
>>>
>>> assertEquals("{\"boundedSet\":[3],\"superList\":[{\"radius\":2.5}]}",
>>> jsonb.toJson(boundedGenericClass));
>>>
>>> I believe it should be:
>>>
>>> {"boundedSet":[3],"superList":[{"area":0.0,"radius":2.5}]}
>>>
>>>
>> Will fix asap.
>>
>>
>>> Have a great Easter!
>>>
>>> Thank you,
>>> Oleg
>>>
>>>
>>
>