support Path in JsonFactory?

63 views
Skip to first unread message

Xeno Amess

unread,
Jan 24, 2022, 11:13:29 PM1/24/22
to jackson-user
Hi.
Is there any reason not support Path in JsonFactory and ObjectMapper?
If not, then I would provide a pr when I have time.

Tatu Saloranta

unread,
Feb 1, 2022, 1:28:52 PM2/1/22
to jackson-user
The main reason is that `Path` was added in JDK 7 and for the longest time Jackson only required JDK 6.

With 2.13 jackson-databind requires JDK 8, so adding support in `ObjectMapper` (and `ObjectReader`) would be fine.

`jackson-core` (JsonFactory / TokenStreamFactory) however still only requires JDK 6 for 2.13, and while
we may consider upgrading the baseline within 2.x no decision has been made (or proposal) for 2.14.
So addition in JsonFactory would not yet be possible.

So, a PR against `2.14` (this is API add so can not go in as part of 2.13.x patches) for `jackson-databind` would be welcome.

Anyone else have comments, suggestions, wrt this question?

-+ Tatu +-

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/96b2fcd7-3f1c-48fa-aadd-15ff6f3b85abn%40googlegroups.com.

Xeno Amess

unread,
Feb 9, 2022, 9:02:28 AM2/9/22
to jackso...@googlegroups.com
Hi.
I checked your 3.0.0-SNAPSHOT branch in databind, which have support to path.
I would like to wait for it.
Thanks.

Tatu Saloranta <tsalo...@gmail.com> 于2022年2月2日周三 02:28写道:

Michael Rogers

unread,
Feb 11, 2022, 7:48:44 AM2/11/22
to jackso...@googlegroups.com, Tatu Saloranta
On 01/02/2022 18:28, Tatu Saloranta wrote:
> On Mon, Jan 24, 2022 at 8:13 PM Xeno Amess <xeno...@gmail.com
> <mailto:xeno...@gmail.com>> wrote:
>
> Hi.
> Is there any reason not support Path in JsonFactory and ObjectMapper?
> If not, then I would provide a pr when I have time.
>
>
> The main reason is that `Path` was added in JDK 7 and for the longest
> time Jackson only required JDK 6.
>
> With 2.13 jackson-databind requires JDK 8, so adding support in
> `ObjectMapper` (and `ObjectReader`) would be fine.
>
> `jackson-core` (JsonFactory / TokenStreamFactory) however still only
> requires JDK 6 for 2.13, and while
> we may consider upgrading the baseline within 2.x no decision has been
> made (or proposal) for 2.14.
> So addition in JsonFactory would not yet be possible.
>
> So, a PR against `2.14` (this is API add so can not go in as part of
> 2.13.x patches) for `jackson-databind` would be welcome.
>
> Anyone else have comments, suggestions, wrt this question?

Older Android devices only have support for the Java 6 standard library.
Some parts of the Java 8 standard library are supported via library
desugaring, but unfortunately Path doesn't seem to be among them:

https://developer.android.com/studio/write/java8-support-table

So adding Path to jackson-databind would make it incompatible with about
3.4% of Android devices (according to apilevels.com). As an app
developer currently using 2.13, this would stop me from upgrading to
2.14 for another couple of years, while those old devices gradually die out.

Cheers,
Michael

> -+ Tatu +-
>
> --
> You received this message because you are subscribed to the Google
> Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to jackson-user...@googlegroups.com
> <mailto:jackson-user...@googlegroups.com>.
> <https://groups.google.com/d/msgid/jackson-user/96b2fcd7-3f1c-48fa-aadd-15ff6f3b85abn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jackson-user...@googlegroups.com
> <mailto:jackson-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jackson-user/CAGrxA24hYAiFW1xymfxBcNRqwYTkEakCm8ikO7bwbeuLdXcwsw%40mail.gmail.com
> <https://groups.google.com/d/msgid/jackson-user/CAGrxA24hYAiFW1xymfxBcNRqwYTkEakCm8ikO7bwbeuLdXcwsw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
OpenPGP_0x11044FD19FC527CC.asc
OpenPGP_signature

Tatu Saloranta

unread,
Feb 11, 2022, 1:45:08 PM2/11/22
to jackso...@googlegroups.com
Ah. This is an interesting data point indeed. Not sure what to make of
it, in the grand
scheme of things, but definitely highly relevant.

There is some code for handling such optional dependencies, but to add
a new "may
exist or may not" dependency requires knowledge on when to add such handling.
Formerly this was used when JDK7 was baseline, but I think 2.x branch
still has it.

However... now I think about this, that actually only helps with
`Json[De]Serializer`s,
but not with core API like ObjectMapper. So never mind, scratch that.

-+ Tatu +-

>
> Cheers,
> Michael
>
> > -+ Tatu +-
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "jackson-user" group.
> > To unsubscribe from this group and stop receiving emails from it,
> > send an email to jackson-user...@googlegroups.com
> > <mailto:jackson-user...@googlegroups.com>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/jackson-user/96b2fcd7-3f1c-48fa-aadd-15ff6f3b85abn%40googlegroups.com
> > <https://groups.google.com/d/msgid/jackson-user/96b2fcd7-3f1c-48fa-aadd-15ff6f3b85abn%40googlegroups.com?utm_medium=email&utm_source=footer>.
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "jackson-user" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to jackson-user...@googlegroups.com
> > <mailto:jackson-user...@googlegroups.com>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/jackson-user/CAGrxA24hYAiFW1xymfxBcNRqwYTkEakCm8ikO7bwbeuLdXcwsw%40mail.gmail.com
> > <https://groups.google.com/d/msgid/jackson-user/CAGrxA24hYAiFW1xymfxBcNRqwYTkEakCm8ikO7bwbeuLdXcwsw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/9268e6fb-931e-a808-0264-4fb493c7f369%40briarproject.org.

jonas....@gmail.com

unread,
Feb 11, 2022, 1:45:13 PM2/11/22
to jackson-user
A missing class for a method parameter shouldn't affect you, you could simply not use that method. If it was a field it'd be a different story.

- Jonas

Xeno Amess

unread,
Feb 11, 2022, 2:41:21 PM2/11/22
to jackso...@googlegroups.com
As far as I know, yes, missing some class in some function's param will not stop you use this class, only when invoking such method would throw ClassNotFoundException

But well that would make jackson-core un-compilable by jdk6, ant I'm not sure would this become an problem.

jonas....@gmail.com <jonas....@gmail.com> 于2022年2月12日周六 02:45写道:
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/2109c03c-15b2-40b7-8b35-afa80b2f6505n%40googlegroups.com.

Tatu Saloranta

unread,
Feb 11, 2022, 5:52:28 PM2/11/22
to jackso...@googlegroups.com
On Fri, Feb 11, 2022 at 10:45 AM jonas....@gmail.com
<jonas....@gmail.com> wrote:
>
> A missing class for a method parameter shouldn't affect you, you could simply not use that method. If it was a field it'd be a different story.
>
> - Jonas

I don't think that is correct in this case? If a method signature for
`ObjectMapper.readValue(Path src, Class<?> target)` is encountered,
I think the class loader will fail to load `ObjectMapper` breaking things.
Or is this not the case?

I do know that if `Path` was known but referred to something else
itself that wasn't, that'd be fine.
But in this particular case I would expect actual trouble even if that
specific `readValue()` method was not called.

-+ Tatu +-
> To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/2109c03c-15b2-40b7-8b35-afa80b2f6505n%40googlegroups.com.

Xeno Amess

unread,
Feb 11, 2022, 8:21:57 PM2/11/22
to jackso...@googlegroups.com
>  I think the class loader will fail to load `ObjectMapper` breaking things.
I don't think so...
Maybe it is worth to have a try

Tatu Saloranta <ta...@fasterxml.com> 于2022年2月12日周六 06:52写道:

Tatu Saloranta

unread,
Feb 11, 2022, 11:02:35 PM2/11/22
to jackson-user
On Fri, Feb 11, 2022 at 5:21 PM Xeno Amess <xeno...@gmail.com> wrote:
>  I think the class loader will fail to load `ObjectMapper` breaking things.
I don't think so...
Maybe it is worth to have a try

Sure, if you want to test this let us know how it goes.
I am curious as to how it could possibly work. :-)

-+ Tatu +-
 

Michael Rogers

unread,
Feb 14, 2022, 6:29:06 AM2/14/22
to jackso...@googlegroups.com, Xeno Amess
On 12/02/2022 01:21, Xeno Amess wrote:
> > I think the class loader will fail to load `ObjectMapper` breaking
> things.
> I don't think so...
> Maybe it is worth to have a try

I gave this a try with a snapshot build, adding a dummy
`readValue(JsonParser, Path, Class<T> valueType)` method to
ObjectMapper. As Jonas and Xeno thought, older Android devices are able
to load and use the ObjectMapper class as long as they don't call this
method.

I don't know whether the dummy method is removed by ProGuard or whether
the reference to Path is resolved lazily by the class loader, but either
way it seems to work.

As another experiment, I modified the `readValue(JsonParser, Class<T>
valueType)` method to call through to the dummy method, using
`Paths.get("/")` to create the Path parameter. My old device was still
able to load and instantiate the ObjectMapper class, but calling the
modified readValue() method caused a NoClassDefFoundError for
java.nio.file.Paths. This suggests that references to unknown classes
can safely exist even if they're not removed by ProGuard, and the class
loader resolves references lazily.

So in short, it looks like adding a method that uses Path is fine, as
long as that class isn't used on any call paths that need to remain
backward compatible.

Cheers,
Michael

> Tatu Saloranta <ta...@fasterxml.com <mailto:ta...@fasterxml.com>> 于2022年
> 2月12日周六 06:52写道:
>
> On Fri, Feb 11, 2022 at 10:45 AM jonas....@gmail.com
> <mailto:jonas....@gmail.com>
> <jonas....@gmail.com <mailto:jonas....@gmail.com>> wrote:
> >
> > A missing class for a method parameter shouldn't affect you, you
> could simply not use that method. If it was a field it'd be a
> different story.
> >
> > - Jonas
>
> I don't think that is correct in this case? If a method signature for
> `ObjectMapper.readValue(Path src, Class<?> target)` is encountered,
> I think the class loader will fail to load `ObjectMapper` breaking
> things.
> Or is this not the case?
>
> I do know that if `Path` was known but referred to something else
> itself that wasn't, that'd be fine.
> But in this particular case I would expect actual trouble even if that
> specific `readValue()` method was not called.
>
> -+ Tatu +-
>
> >
> > Michael Rogers schrieb am Freitag, 11. Februar 2022 um 13:48:44
> UTC+1:
> >>
> >> On 01/02/2022 18:28, Tatu Saloranta wrote:
> >> > On Mon, Jan 24, 2022 at 8:13 PM Xeno Amess <xeno...@gmail.com
> <mailto:xeno...@gmail.com>
> <http://apilevels.com>). As an app
> >> developer currently using 2.13, this would stop me from upgrading to
> >> 2.14 for another couple of years, while those old devices
> gradually die out.
> >>
> >> Cheers,
> >> Michael
> >>
> >> > -+ Tatu +-
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "jackson-user" group.
> >> > To unsubscribe from this group and stop receiving emails from it,
> >> > send an email to jackson-user...@googlegroups.com
> <mailto:jackson-user...@googlegroups.com>
> >> > <mailto:jackson-user...@googlegroups.com
> <https://groups.google.com/d/msgid/jackson-user/96b2fcd7-3f1c-48fa-aadd-15ff6f3b85abn%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/jackson-user/96b2fcd7-3f1c-48fa-aadd-15ff6f3b85abn%40googlegroups.com?utm_medium=email&utm_source=footer>>.
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups "jackson-user" group.
> >> > To unsubscribe from this group and stop receiving emails from
> it, send
> >> > an email to jackson-user...@googlegroups.com
> <mailto:jackson-user...@googlegroups.com>
> >> > <mailto:jackson-user...@googlegroups.com
> <https://groups.google.com/d/msgid/jackson-user/CAGrxA24hYAiFW1xymfxBcNRqwYTkEakCm8ikO7bwbeuLdXcwsw%40mail.gmail.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/jackson-user/CAGrxA24hYAiFW1xymfxBcNRqwYTkEakCm8ikO7bwbeuLdXcwsw%40mail.gmail.com?utm_medium=email&utm_source=footer>>.
> >
> > --
> > You received this message because you are subscribed to the
> Google Groups "jackson-user" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send an email to jackson-user...@googlegroups.com
> <mailto:jackson-user%2Bunsu...@googlegroups.com>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/jackson-user/2109c03c-15b2-40b7-8b35-afa80b2f6505n%40googlegroups.com
> <https://groups.google.com/d/msgid/jackson-user/2109c03c-15b2-40b7-8b35-afa80b2f6505n%40googlegroups.com>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to jackson-user...@googlegroups.com
> <mailto:jackson-user%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jackson-user/CAL4a10hZ3n_Kuh8Ns8nQ-S0Yk26%2BE3nbFQa1NTJouUmOd%2Bu2TQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/jackson-user/CAL4a10hZ3n_Kuh8Ns8nQ-S0Yk26%2BE3nbFQa1NTJouUmOd%2Bu2TQ%40mail.gmail.com>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jackson-user...@googlegroups.com
> <mailto:jackson-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jackson-user/CAFF4x5KKU0OVfMHPt63qRB58Lgm18-c4x4ZF11R%2BLr7qYfDMYQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/jackson-user/CAFF4x5KKU0OVfMHPt63qRB58Lgm18-c4x4ZF11R%2BLr7qYfDMYQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
OpenPGP_0x11044FD19FC527CC.asc
OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages