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]这个是?这样不是很奇怪吗? #2093

Closed
oooopl opened this issue Dec 13, 2023 · 5 comments
Closed

[BUG]这个是?这样不是很奇怪吗? #2093

oooopl opened this issue Dec 13, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@oooopl
Copy link

oooopl commented Dec 13, 2023

version:fastjson2-2.0.43
image

@oooopl oooopl added the bug Something isn't working label Dec 13, 2023
@oooopl
Copy link
Author

oooopl commented Dec 14, 2023

我是全局配置了dateFormat,但是如果发现是 LocalTime,不应该使用全局dateFormat的时间这部分的格式吗
难道要给每个 LocalTime字段都加上 @JSONField(format = "xx")?
如果是 Map,List 这种数据结构 怎么加JSONField,指定 serializeUsing?

@oooopl
Copy link
Author

oooopl commented Dec 14, 2023

有点火大,JSON.register一个 writer 又会让 @JSONField(format = "xx")失效,因为 format 没有交传给 writer
com.alibaba.fastjson2.writer.FieldWriter#getObjectWriter(java.lang.reflect.Type, java.lang.Class, java.lang.String, java.util.Locale, java.lang.Class)
image

@oooopl
Copy link
Author

oooopl commented Dec 14, 2023

还有一个问题 #2060 2060 这个需求怎么实现?

@oooopl oooopl changed the title [BUG]这个是? [BUG]这个是?这样不是很奇怪吗? Dec 14, 2023
@wenshao
Copy link
Member

wenshao commented Dec 23, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.44-SNAPSHOT/
这个版本已经支持List/Map类型的@JSONField(format="HH:mm:ss")这样的配置

@wenshao
Copy link
Member

wenshao commented Dec 23, 2023

    @Data
    public static class Bean {
        @JSONField(format = "HH:mm:ss")
        private List<LocalDateTime> times;

        @JSONField(format = "HH:mm:ss")
        private Map<String, LocalDateTime> timeMap;
    }

        ObjectWriterProvider provider = new ObjectWriterProvider();
        BeanInfo beanInfo = new BeanInfo();
        FieldInfo fieldInfo = new FieldInfo();
        Class beanClass = Bean.class;
        Method method = beanClass.getMethod("getTimes");
        provider.getFieldInfo(beanInfo, fieldInfo, beanClass, method);

如上这样的方式可以读取到format

@oooopl oooopl closed this as completed Dec 28, 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
Projects
None yet
Development

No branches or pull requests

2 participants