Skip to content

Make JsonLineMapper agnostic to the JSON library - #5345

Closed
quaff wants to merge 1 commit into
spring-projects:mainfrom
quaff:patch-58
Closed

quaff wants to merge 1 commit into
spring-projects:mainfrom
quaff:patch-58

Conversation

@quaff

@quaff quaff commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

It's related to #5344.

It's related to spring-projects#5344.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
@fmbenhassine

Copy link
Copy Markdown
Contributor

Thank you for this PR and for #5344, @quaff! Making JsonLineMapper able to map lines to any type is a good addition, and it pairs well with the new JsonLineAggregator. While reviewing both, I noticed an inconsistency in the design.

JsonLineAggregator is agnostic to the JSON library: it delegates to a JsonObjectMarshaller, so users can choose the Jackson or Gson implementation (or their own). As proposed here, JsonLineMapper is tied to Jackson (JsonMapper, TypeReference), so a Gson-only user can't use it, and the reader and writer sides don't have the same shape.

Making JsonLineMapper generic is already a source and binary breaking change (mapLine no longer returns Map<String, Object>). Since we are breaking things anyway, I would rather take the opportunity to get the design right than keep the Jackson coupling. The direction is:

  • Introduce a JsonObjectUnmarshaller<T> interface, the counterpart of JsonObjectMarshaller, with T unmarshal(String json).
  • Provide JacksonJsonObjectUnmarshaller and GsonJsonObjectUnmarshaller implementations.

The generic JsonLineMapper<T> and the domain-type test from this PR carry over to the new design. Because the shape of the change differs from what is proposed here, I will implement it myself rather than ask you to rework the PR, and I will credit you as a co-author on the commit. For that reason I am going to close this PR once the commit is in.

#5344 is independent of this change and is not affected. Thanks again for the contribution, and feel free to comment if you see an issue with this direction.

fmbenhassine added a commit that referenced this pull request Oct 15, 2026
Introduce JsonObjectUnmarshaller, the counterpart of JsonObjectMarshaller,
with Jackson and Gson implementations. JsonLineMapper is now generic and
delegates the conversion of a line to a JsonObjectUnmarshaller, which lets
it map lines to any type with any JSON library, like JsonLineAggregator.

The no-arg and JsonMapper constructors of JsonLineMapper are deprecated for
removal in favor of JsonLineMapper(JsonObjectUnmarshaller).

Related to #5344 and #5345.

Co-authored-by: Yanming Zhou <zhouyanming@gmail.com>
@fmbenhassine

Copy link
Copy Markdown
Contributor

Implemented in 8ae657a, with credits to you as well.

Thank you very much for your contribution!

@fmbenhassine fmbenhassine changed the title Allow to create JsonLineMapper with provided target type other than Map Make JsonLineMapper agnostic to the JSON library Oct 15, 2026
@fmbenhassine fmbenhassine added this to the 6.1.0-RC1 milestone Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants