fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG] JSONB.parseObject with date relevant types throws TODO

Open Cooperzzy opened this issue 1 year ago • 0 comments

问题描述

一些时间相关的类使用JSONB.parseObject解析会抛出 com.alibaba.fastjson2.JSONException: TODO 使用JSON.parseObject会附带信息,建议完善报错信息:) 相关代码应该在JSONReaderJSONB.readLocalDateTime0和readLocalDate0

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson2 2.0.52]

重现步骤

import com.alibaba.fastjson2.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.stream.Stream;

public class Test_291 {

    static Stream<Class<?>> dateTypes() {
        return Stream.of(
                Bean1.class,
                Bean2.class,
                Bean3.class,
                Bean4.class
        );
    }

    @ParameterizedTest
    @MethodSource("dateTypes")
    public void testJSONBParsing(Class<?> beanClass) {
        byte[] bytes = JSONB.toBytes(JSONObject.of("date", "2020-01-01  "));
        System.out.println(JSONB.parseObject(bytes, beanClass));
    }

    @ParameterizedTest
    @MethodSource("dateTypes")
    public void testJSONParsing(Class<?> beanClass) {
        String json = JSON.toJSONString(JSONObject.of("date", "2020-01-01  "));
        System.out.println(JSON.parseObject(json, beanClass));
    }


    public static class Bean1 {
        public java.sql.Date date;
    }

    public static class Bean2 {
        public java.sql.Timestamp date;
    }

    public static class Bean3 {
        public java.time.LocalDateTime date;
    }

    public static class Bean4 {
        public java.time.LocalDate date;
    }
}

相关日志输出

com.alibaba.fastjson2.JSONException: TODO :

Cooperzzy avatar Jul 28 '24 13:07 Cooperzzy