Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

关于Bean序列化与反序列化Map<String,String>中属性Date类型值为1970年前的问题能否优化? #1772

@xman54

Description

@xman54

Map<String,String> hash = JSONObject.parseObject(JSON.toJSONString(bean), new TypeReference<Map<String, String>>(){});
方法可以将Bean序列化成Map<String,String>。

JSONObject.toJavaObject((JSONObject)JSON.toJSON(hash),clazz);
方法反序列化成Bean时,如果属性类型为Date值为1970年以前时间时,会报序列化失败。看了下是com.alibaba.fastjson.util.TypeUils类中castToDate方法第307行代码针对format的处理有些问题,不支持“--355132800000”字符串的处理。

建议307行判断条件改为: if(strVal.indexOf('-',1) != -1){

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions