Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]Duration属性对象序列化后,反序列化异常 #1499

Closed
lyhu opened this issue May 19, 2023 · 2 comments
Closed

[BUG]Duration属性对象序列化后,反序列化异常 #1499

lyhu opened this issue May 19, 2023 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@lyhu
Copy link

lyhu commented May 19, 2023

问题描述

Duration属性对象序列化后,反序列化异常

环境信息

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.32]

重现步骤

如何操作可以重现该问题:

  1. 使用 JSON.parseObject 方法
    @Data
    static class ConfigItem {
        @JSONField(ordinal = 30)
        @DurationUnit(ChronoUnit.SECONDS)
        private Duration handleTimeout = Duration.ofSeconds(10);


        @JSONField(ordinal = 60)
        private String name = "li4";

        public ConfigItem clone() {
            return JSON.parseObject(JSON.toJSONBytes(this), ConfigItem.class);
        }
    }

    public static void main(String[] args) {
        ConfigItem configItem = new ConfigItem();
        System.out.println(configItem);
        ConfigItem configItem2 = configItem.clone();
        System.out.println(configItem2);
    }

期待的正确结果

能正常clone

相关日志输出

MqManager.ConfigItem(handleTimeout=PT10S, name=li4)
Exception in thread "main" com.alibaba.fastjson2.JSONException: expect ':', but 44, offset 67, character ", line 1, column 68, fastjson-version 2.0.32 {"handleTimeout":{"nano":0,"negative":false,"seconds":10,"units":["SECONDS","NANOS"],"zero":false},"name":"li4"}
	at com.alibaba.fastjson2.JSONReaderUTF8.readFieldNameHashCode(JSONReaderUTF8.java:872)
	at com.alibaba.fastjson2.reader.ObjectReaderInterface.readObject(ObjectReaderInterface.java:140)
	at com.alibaba.fastjson2.reader.ObjectReaderImplList.readObject(ObjectReaderImplList.java:561)
	at com.alibaba.fastjson2.reader.FieldReaderCollectionMethodReadOnly.readFieldValue(FieldReaderCollectionMethodReadOnly.java:112)
	at com.alibaba.fastjson2.reader.ObjectReader1.readObject(ObjectReader1.java:275)
	at com.alibaba.fastjson2.reader.ORG_1_2_ConfigItem.readObject(Unknown Source)
	at com.alibaba.fastjson2.JSON.parseObject(JSON.java:1307)
@lyhu lyhu added the bug Something isn't working label May 19, 2023
@wenshao wenshao added this to the 2.0.33 milestone May 20, 2023
@wenshao
Copy link
Member

wenshao commented May 20, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.33-SNAPSHOT/
问题已修复,请帮忙用2.0.33-SNAPSHOT版本验证。

@wenshao wenshao added the fixed label May 20, 2023
@wenshao
Copy link
Member

wenshao commented May 29, 2023

@wenshao wenshao closed this as completed May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants