Skip to content

Design a Jackson 2/3 Compatibility Adapter Layer for Nacos to Support Spring 4.x and AI Ecosystem #14466

@KomachiSion

Description

@KomachiSion

Is your feature request related to a problem? Please describe.

jackson发布了3.x版本,且和2.x版本有较大的不兼容问题。

spring 官方在4.x版本中将jackson升级到了3.x版本, 这可能导致spring cloud和spring ai在新版本中默认依赖了jackson3.x版本。

nacos-client在这种情况下,如果仅依赖2.x版本的jackson,能导致和spring-boot4 以及对应新版本的spring cloud和spring ai存在不兼容的问题。但Nacos有不能直接升级成3.x版本的jackson,因为还有用户留存在2.x版本的jackson以及spring-boot3及更老的版本中。

Describe the solution you'd like

因此这里需要抽象一个Jackson或者Json的适配层,自动识别当前的jackson版本,然后使用对应版本的api进行操作。

目前Nacos的Json序列化和反序列化操作基本都收敛在JsonUtil中,相对来说改造成本比较低。欢迎社区同学提供方案和PR。

设计方案和PR时,请注意以下几点要点:

  1. 建议抽象出一个适配层API,供JsonUtil使用。
  2. 可以通过判断特征类是否存在的方式,判断应该用Jackson3还是2。
  3. 考虑到用户可能不是使用的spring框架,默认还是需要依赖jackson2作为默认选项。
  4. 尽量降低对用户的升级的影响。

Describe alternatives you've considered

  • 直接升级jackson到3.x,但对存量用户兼容性风险高,不建议。
  • 维持当前实现,但不支持spring-boot4/AI生态新版本,也不利于后续演进。

Additional context

社区同学可在此issue发布设计方案或直接提交PR,欢迎补充、讨论。


jackson 3.x is released and has major incompatibilities with version 2.x.
Spring 4.x has upgraded to jackson 3.x, which may lead to new versions of spring cloud/ai defaulting to jackson 3.x.
Currently, nacos-client only depending on jackson 2.x would cause incompatibility with spring-boot 4.x and new versions of spring cloud/ai, but Nacos cannot simply upgrade to jackson 3.x because some users are still using jackson 2.x or spring-boot 3.x/older.

A json-adapter layer is suggested to detect the present jackson version dynamically and delegate to the appropriate api, with main serialization logic already converged in JsonUtil (making the refactor cost manageable).

When designing or submitting a PR, please consider:

  1. Abstracting an adapter API for JsonUtil.
  2. Identifying jackson version via feature class detection.
  3. Defaulting to jackson2 for non-spring users as the safer option.
  4. Minimizing user upgrade impact as much as possible.

Related design suggestions and PRs are welcome under this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementCategory issues or prs related to enhancement.kind/featuretype/feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions