Skip to content

[BUG] #2578 Serialize java.awt.Color  #2739

@Cooperzzy

Description

@Cooperzzy

问题描述

#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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions