Skip to content

Conversation

@eranl
Copy link

@eranl eranl commented Oct 18, 2025

Make @JsonAnySetter creator properties behave similarly to non-creator ones, using a LinkedHashMap.
Since the arguments are stored in a reverse-order singly-linked list, I used recursion to restore the original order. Any better way to do it?

Fixes #5353.

@cowtowncoder
Copy link
Member

I think we'd first need an issue explaining what is the problem to fix.

@cowtowncoder
Copy link
Member

Ok, use of LinkedHashMap in itself is acceptable, retaining order possibly useful, with modest (probably non-measurable) overhead.

But adding overhead of reordering for every use is not good -- many users would get penalized despite not caring about ordering.

So if we can figure out how to insert values in order, +1.

@JooHyukKim knows this area pretty well and can probably help.

@eranl
Copy link
Author

eranl commented Oct 20, 2025

But adding overhead of reordering for every use is not good -- many users would get penalized despite not caring about ordering.

You mean the recursion? Is that measurable?

@cowtowncoder
Copy link
Member

But adding overhead of reordering for every use is not good -- many users would get penalized despite not caring about ordering.

You mean the recursion? Is that measurable?

No I mean reordering in general; should be possible to just retain insert order without essentially ordering twice.

@eranl
Copy link
Author

eranl commented Oct 20, 2025

The only change I made there was replacing iteration with recursion.

@cowtowncoder
Copy link
Member

The only change I made there was replacing iteration with recursion.

Hmh. Ok, I probably need to re-read PR.

But yes, recursion on its own can also be problematic wrt security aspects (stack overflow) so ideally not usad with linear data structures.

@cowtowncoder
Copy link
Member

Ok yes, recursion to re-order, since it's effectively linked list. Hmmh.
I'll have to think about, no obvious better way to go about that.

@JooHyukKim
Copy link
Member

JooHyukKim commented Oct 21, 2025

Sorry late reply.

  1. Iteration does sound safer than recursion, since anySetter pretty much as no limit to size.
  2. Another question is... would it be possible fixing the way data is passed to record the record? @cowtowncoder Simply reversing back sounds okay, but seems hacky instead of fixing the actual problem/or issue
  3. If we do add order-preservation, need to add a new feature (unless performance is preserved)

@eranl
Copy link
Author

eranl commented Oct 21, 2025

I considered replacing the linked list with some List, but that seemed like a big change. Happy to do it if you guys think it's the right way to go.

@cowtowncoder
Copy link
Member

I'm not happy with recursion due to possible stack exhaustion. But adding an extra data structure not great either.

I think we need to have this as opt-in (DeserializationFeature) for this, to explicitly enable.

@eranl
Copy link
Author

eranl commented Oct 21, 2025

adding an extra data structure not great either.

I'm proposing a replacement data structure, not an extra one.

@cowtowncoder
Copy link
Member

One other note: while retaining order sounds like an improvement, it also has some backwards-compatibility aspects so I think that actual change should probably go against 3.x branch, not 2.x.
We are just now switching to focusing 2.x on particularly low-risk fixes, changes, and most new features (and riskier changes) to 3.x only.
(basically we will merge forward from 2.x to 3.x quite easily but not the reverse).

So, if -- for example, PropertyValueBuffer buffering was changed from reverse-linked (or, prepend-only) to append-linked (so "head" and "tail" pointers) to retain ordering for all buffered properties -- this would seem potentially risky for some usage: while users should NOT rely on ordering of deserialization during buffering, it's almost guaranteed someone somewhere is relying on it (likely unintentionally/unknowingly).

But +1 for improved data structure, fix against 3.x.

@eranl
Copy link
Author

eranl commented Oct 24, 2025

I guess that makes sense, but it requires that I upgrade to v3 first, so it'll take a while...

@cowtowncoder
Copy link
Member

I guess that makes sense, but it requires that I upgrade to v3 first, so it'll take a while...

Understood.

@cowtowncoder cowtowncoder added the 3.x Issues to be only tackled for Jackson 3.x, not 2.x label Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Issues to be only tackled for Jackson 3.x, not 2.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants