fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG] #2578 Serialize java.awt.Color

Open Cooperzzy opened this issue 1 year ago • 0 comments

问题描述

#2578 , 1.x 支持但fastjson 2.0.51兼容有问题。

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson 2.0.51]

重现步骤


import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test;

import java.awt.Color;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2578 {
    @Test
    public void test() {
        Color blue = Color.BLUE;
        String colorStr = JSON.toJSONString(blue);
        assertEquals("{\"r\":0,\"g\":0,\"b\":255,\"alpha\":255}", colorStr);
        Color color = JSON.parseObject(colorStr, Color.class);
        assertEquals(blue, color);
    }
}

期待的正确结果

Expected :{"r":0,"g":0,"b":255,"alpha":255} Actual :{"rgb":-16776961}

Cooperzzy avatar Jun 25 '24 14:06 Cooperzzy