alibaba / alibaba/fastjson2

[QUESTION]JSON.register有无通过基类或接口来注册自定义的序列化、反序列化类的方法?

Open
#875 6 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

`JSON.register`注册自定义的类型序列化,反序列化类时,能根据对象的基类或接口类来注册而不是一个一个类注册吗?

1、我自己定义了很多的枚举,都继承了一个统一的接口,我在vo里面返回到前端时,希望对象里面的枚举属性显示为接口中某方法的返回值。目前在2.0.16中通过自定义ObjectWriter,然后每个枚举进行一次`JSON.register`来达到这个效果。但是如果后面自定义枚举越来越多,再每个进行`JSON.register`就显得代码臃肿了,时间了也可能忘记这个操作。

2、以后会实现自己的JSONValue注解而不是引用jackson的JsonValue注解吗?两边的大小写策略不一致,强迫症有点难受,而且本来引用fastjson就能完事的,还得引个jackson-annoations就有点小亏。

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the JSON.register and custom ObjectWriter behavior in fastjson2 2.0.16, focusing on whether registration can match a shared enum interface or base type. Also check the current handling of Jackson's JsonValue annotation. Done means determining whether either request is supported, planned, or requires a scoped design proposal.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.