incubator-seata icon indicating copy to clipboard operation
incubator-seata copied to clipboard

feature: unify Jackson/fastjson serialization.

Open LegendPei opened this issue 1 month ago • 4 comments

Ⅰ. Describe what this PR did

unify Jackson/fastjson serialization

Modules involved: integration-tx-api seata-saga-statelang tcc

API interface:

classDiagram
    class JsonSerializer {
        <<interface>>
        +String toJSONString(Object object)
        +T parseObject(String text, Class~T~ clazz)
        +T parseObject(String text, Type type)
    }
    
    class JsonUtil {
        -JsonSerializer serializer
        +JsonUtil(JsonSerializer serializer)
        +String toJSONString(Object object)
        +T parseObject(String text, Class~T~ clazz)
        +T parseObject(String text, Type type)
        +JsonSerializer getSerializer()
    }
    
    class JsonSerializerFactory {
        <<static>>
        +JsonSerializer getSerializer(String name)
    }
    
    class FastjsonJsonSerializer {
        +String toJSONString(Object object)
        +T parseObject(String text, Class~T~ clazz)
        +T parseObject(String text, Type type)
        +String toJSONString(Object object, boolean prettyPrint)
        +String toJSONString(Object object, boolean ignoreAutoType, boolean prettyPrint)
        +T parseObject(String text, Class~T~ type, boolean ignoreAutoType)
        +boolean useAutoType(String json)
    }
    
    class JacksonJsonSerializer {
        +String toJSONString(Object object)
        +T parseObject(String text, Class~T~ clazz)
        +T parseObject(String text, Type type)
        +String toJSONString(Object object, boolean prettyPrint)
        +String toJSONString(Object object, boolean ignoreAutoType, boolean prettyPrint)
        +T parseObject(String text, Class~T~ type, boolean ignoreAutoType)
        +boolean useAutoType(String json)
    }
    
    class GsonJsonSerializer {
        +String toJSONString(Object object)
        +T parseObject(String text, Class~T~ clazz)
        +T parseObject(String text, Type type)
        +String toJSONString(Object object, boolean prettyPrint)
        +String toJSONString(Object object, boolean ignoreAutoType, boolean prettyPrint)
        +T parseObject(String text, Class~T~ type, boolean ignoreAutoType)
        +boolean useAutoType(String json)
    }
    
    JsonUtil --> JsonSerializer : uses
    JsonSerializerFactory --> JsonSerializer : creates
    FastjsonJsonSerializer ..|> JsonSerializer : implements
    JacksonJsonSerializer ..|> JsonSerializer : implements  
    GsonJsonSerializer ..|> JsonSerializer : implements

Use flowcharts: mermaid-diagram-2025-11-02-201407

Ⅱ. Does this pull request fix one issue?

fixes #7554

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

LegendPei avatar Nov 02 '25 12:11 LegendPei

Codecov Report

:x: Patch coverage is 77.97619% with 37 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 71.06%. Comparing base (b27e6be) to head (a9589ad).

Files with missing lines Patch % Lines
...che/seata/common/json/impl/GsonJsonSerializer.java 65.71% 11 Missing and 1 partial :warning:
...seata/common/json/impl/FastjsonJsonSerializer.java 74.35% 7 Missing and 3 partials :warning:
.../saga/engine/serializer/impl/ParamsSerializer.java 50.00% 2 Missing and 2 partials :warning:
.../seata/common/json/impl/JacksonJsonSerializer.java 94.64% 1 Missing and 2 partials :warning:
.../statelang/parser/impl/StateMachineParserImpl.java 40.00% 2 Missing and 1 partial :warning:
...in/java/org/apache/seata/common/json/JsonUtil.java 80.00% 1 Missing and 1 partial :warning:
.../engine/invoker/impl/SpringBeanServiceInvoker.java 66.66% 1 Missing and 1 partial :warning:
.../apache/seata/rm/datasource/ConnectionContext.java 66.66% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #7760      +/-   ##
============================================
+ Coverage     71.03%   71.06%   +0.02%     
  Complexity      797      797              
============================================
  Files          1294     1299       +5     
  Lines         49528    49672     +144     
  Branches       5873     5884      +11     
============================================
+ Hits          35182    35299     +117     
- Misses        11437    11466      +29     
+ Partials       2909     2907       -2     
Files with missing lines Coverage Δ
...egration/tx/api/interceptor/ActionContextUtil.java 56.36% <ø> (ø)
...n/tx/api/interceptor/ActionInterceptorHandler.java 74.25% <ø> (ø)
...he/seata/rm/tcc/api/BusinessActionContextUtil.java 40.00% <ø> (ø)
...pache/seata/common/json/JsonSerializerFactory.java 100.00% <100.00%> (ø)
...tatelang/parser/utils/DesignerJsonTransformer.java 67.27% <100.00%> (ø)
.../apache/seata/rm/datasource/ConnectionContext.java 76.56% <66.66%> (ø)
...in/java/org/apache/seata/common/json/JsonUtil.java 80.00% <80.00%> (ø)
.../engine/invoker/impl/SpringBeanServiceInvoker.java 67.97% <66.66%> (ø)
.../seata/common/json/impl/JacksonJsonSerializer.java 94.64% <94.64%> (ø)
.../statelang/parser/impl/StateMachineParserImpl.java 70.49% <40.00%> (ø)
... and 3 more

... and 11 files with indirect coverage changes

Impacted file tree graph

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 02 '25 13:11 codecov[bot]

Are you developing based on an old branch? It would be better to use a new branch next time; otherwise, there will be many commits that don't belong to this pull request, which is detrimental to CR

maple525866 avatar Nov 02 '25 14:11 maple525866

Are you developing based on an old branch? It would be better to use a new branch next time; otherwise, there will be many commits that don't belong to this pull request, which is detrimental to CR您是否基于旧分支进行开发?下次最好使用一个新的分支;否则,将有许多提交不属于这个pull请求,这对CR是有害的

Yes, sorry, I forgot to reset when I created the new branch earlier, so there are some unnecessary commits : (

LegendPei avatar Nov 02 '25 14:11 LegendPei

I’d really appreciate any feedback or suggestions from the community. orz I’m currently working on improving test coverage for this patch, and if all goes well, I plan to gradually replace the existing JsonUtil usages in other modules as well :)

LegendPei avatar Nov 02 '25 15:11 LegendPei