Change rest-http Java to JSON null transformation logic

classic Classic list List threaded Threaded
10 messages Options
Alexey Kuznetsov Alexey Kuznetsov
Reply | Threaded
Open this post in threaded view
|

Change rest-http Java to JSON null transformation logic

Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?


Vladislav Pyatkov Vladislav Pyatkov
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

Hello,

Why do you want this, if you can save full compatibility using custom serializer for null value (ObjectMapper#setSerializerProvider)?

On Thu, Jun 16, 2016 at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:
Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?



Pavel Tupitsyn Pavel Tupitsyn
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

Hi,

What if there is an actual string with "null" value?

Pavel.

On Thu, Jun 16, 2016 at 12:44 PM, Vladislav Pyatkov <[hidden email]> wrote:
Hello,

Why do you want this, if you can save full compatibility using custom serializer for null value (ObjectMapper#setSerializerProvider)?

On Thu, Jun 16, 2016 at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:
Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?




Denis Magda Denis Magda
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

In reply to this post by Alexey Kuznetsov
This looks strange. Definitely for consistency reasons it makes sense that all ‘null’ objects including string are serialized as “null”.

In regards to the compatibility stuff I think it can be resolved somehow. 

Denis

On Jun 16, 2016, at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:

Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?



Pavel Tupitsyn Pavel Tupitsyn
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

Why do we even write null fields? Can we just omit them?
This will be faster, more compact, and less ambiguous.

Pavel.

On Thu, Jun 16, 2016 at 12:51 PM, Denis Magda <[hidden email]> wrote:
This looks strange. Definitely for consistency reasons it makes sense that all ‘null’ objects including string are serialized as “null”.

In regards to the compatibility stuff I think it can be resolved somehow. 

Denis

On Jun 16, 2016, at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:

Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?




Alexey Kuznetsov Alexey Kuznetsov
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

In reply to this post by Vladislav Pyatkov
Vlad, 

Actually I implemented 2 custom serializers: one for null strings and another for null objects.
But I think that it looks like a "workaround" for me.

On Thu, Jun 16, 2016 at 4:44 PM, Vladislav Pyatkov <[hidden email]> wrote:
Hello,

Why do you want this, if you can save full compatibility using custom serializer for null value (ObjectMapper#setSerializerProvider)?

On Thu, Jun 16, 2016 at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:
Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?






--
Alexey Kuznetsov
GridGain Systems
www.gridgain.com
Alexey Kuznetsov Alexey Kuznetsov
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

In reply to this post by Pavel Tupitsyn
Pavel, in this case object will be serialized like : {"a": "null"} compare with {"a": null}

On Thu, Jun 16, 2016 at 4:49 PM, Pavel Tupitsyn <[hidden email]> wrote:
Hi,

What if there is an actual string with "null" value?

Pavel.

On Thu, Jun 16, 2016 at 12:44 PM, Vladislav Pyatkov <[hidden email]> wrote:
Hello,

Why do you want this, if you can save full compatibility using custom serializer for null value (ObjectMapper#setSerializerProvider)?

On Thu, Jun 16, 2016 at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:
Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?







--
Alexey Kuznetsov
GridGain Systems
www.gridgain.com
Alexey Kuznetsov Alexey Kuznetsov
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

In reply to this post by Pavel Tupitsyn
Pavel, we cannot omit them.

Because if JSON will be transformed back to Java and some java field has not null default value that will lead to not correct de-serialization in this case.

On Thu, Jun 16, 2016 at 4:54 PM, Pavel Tupitsyn <[hidden email]> wrote:
Why do we even write null fields? Can we just omit them?
This will be faster, more compact, and less ambiguous.

Pavel.

On Thu, Jun 16, 2016 at 12:51 PM, Denis Magda <[hidden email]> wrote:
This looks strange. Definitely for consistency reasons it makes sense that all ‘null’ objects including string are serialized as “null”.

In regards to the compatibility stuff I think it can be resolved somehow. 

Denis

On Jun 16, 2016, at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:

Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?







--
Alexey Kuznetsov
GridGain Systems
www.gridgain.com
Pavel Tupitsyn Pavel Tupitsyn
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

Alexey, got it regarding "null" string, thank you.

Can you elaborate on non-null default values? Is it only for primitive types, or something else?
Anyway, can we omit fields with default values? I have seen some serializers that work this way.

Pavel.

On Thu, Jun 16, 2016 at 1:05 PM, Alexey Kuznetsov <[hidden email]> wrote:
Pavel, we cannot omit them.

Because if JSON will be transformed back to Java and some java field has not null default value that will lead to not correct de-serialization in this case.

On Thu, Jun 16, 2016 at 4:54 PM, Pavel Tupitsyn <[hidden email]> wrote:
Why do we even write null fields? Can we just omit them?
This will be faster, more compact, and less ambiguous.

Pavel.

On Thu, Jun 16, 2016 at 12:51 PM, Denis Magda <[hidden email]> wrote:
This looks strange. Definitely for consistency reasons it makes sense that all ‘null’ objects including string are serialized as “null”.

In regards to the compatibility stuff I think it can be resolved somehow. 

Denis

On Jun 16, 2016, at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:

Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?







--
Alexey Kuznetsov
GridGain Systems
www.gridgain.com

Alexey Kuznetsov Alexey Kuznetsov
Reply | Threaded
Open this post in threaded view
|

Re: Change rest-http Java to JSON null transformation logic

In reply to this post by Denis Magda
Den, that was my main reason "consistency". Strings in java can be "null" and can be empty. But after serialization we lost this info.
As for compatibility - I'm afraid it is impossible to fix. Only to change user code.

On Thu, Jun 16, 2016 at 4:51 PM, Denis Magda <[hidden email]> wrote:
This looks strange. Definitely for consistency reasons it makes sense that all ‘null’ objects including string are serialized as “null”.

In regards to the compatibility stuff I think it can be resolved somehow. 

Denis

On Jun 16, 2016, at 12:15 PM, Alexey Kuznetsov <[hidden email]> wrote:

Hi All!

I'm working on migrating from outdated json-lib to Jackson issue IGNITE-3277 [1] and found that previous library serialize null strings as "" and null objects as "null", for example:
{"a": "", "b": null}

How about to serialize all values as "null" ?
In this case we would definitely know that in Java before serialization to JSON was really NULL, not empty string.

But this may break compatibility in some cases.

Thoughts?






--
Alexey Kuznetsov
GridGain Systems
www.gridgain.com