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] #1789

Closed
imJYZ opened this issue Aug 25, 2023 · 3 comments
Closed

[BUG] #1789

imJYZ opened this issue Aug 25, 2023 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@imJYZ
Copy link

imJYZ commented Aug 25, 2023

问题描述

简要描述您碰到的问题。

ZoneOffset 序列化之后的内容,再反序列化回去报错。
报错信息:

com.alibaba.fastjson2.JSONException: expect ':', but }, offset 15, character ", line 1, column 16, fastjson-version 2.0.39 {"zoneOffset":"+08:00"}
	at com.alibaba.fastjson2.JSONReaderUTF16.readFieldNameHashCode(JSONReaderUTF16.java:1618)
	at com.alibaba.fastjson2.reader.ObjectReaderBean.readObject(ObjectReaderBean.java:266)
	at com.alibaba.fastjson2.reader.ORG_1_9_Person.readObject(Unknown Source)
	at com.alibaba.fastjson2.JSON.parseObject(JSON.java:726)
	at org.example.JacksonTest.main(JacksonTest.java:52)

环境信息

  • JDK信息: 1.8
  • 版本信息:Fastjson2 2.0.39

重现步骤

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

  1. 使用 JSON.toJSONString() 方法
  2. 拿toJSONString的结果放到 JSON.parseObject(String text, Class<T> clazz) 中解析
@Data
class Person{
    private String name;
    private Integer age;
    private Object object;
    private Date date;
    private Duration duration;
    private LocalTime localTime;
    private LocalDate localDate;
    private LocalDateTime localDateTime;
    private ZoneOffset zoneOffset = ZoneOffset.ofHours(8);
}

public static void main(String[] args) throws IOException {
    Person person = new Person();
    person.setZoneOffset(ZoneOffset.ofHours(8));
    String str =  JSON.toJSONString(person); // {"zoneOffset":"+08:00"}
    JSON.parseObject(str, Person.class);
}
@imJYZ imJYZ added the bug Something isn't working label Aug 25, 2023
@wenshao wenshao added this to the 2.0.40 milestone Aug 26, 2023
@wenshao
Copy link
Member

wenshao commented Aug 26, 2023

@wenshao wenshao added the fixed label Aug 26, 2023
@imJYZ
Copy link
Author

imJYZ commented Aug 28, 2023

已验证,没问题。

@imJYZ imJYZ closed this as completed Aug 28, 2023
@wenshao
Copy link
Member

wenshao commented Sep 3, 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