extent-framework / extentreports-java

Extent Reporting Library, Java
http://extentreports.com
Apache License 2.0
220 stars 126 forks source link

Gson unable to parse date/time - Question marks in timestamp (e.g. 10:31:12?AM) #402

Open therille opened 1 year ago

therille commented 1 year ago

I am getting "?" (question marks) in timestamp (e.g. 10:31:12?AM) only on ViewName.TEST page. Please check the screenshot: Screenshot_1

I am using 5.1.0 version, but I was getting "?" in the previous versions, also (in some versions on different places, but only on Test page, and only on timestamps). It prevents me from appending reports, because Gson parser can not load and parse existing .json file (containing previous reports) with those question marks in timestamps.

My configuration is the following:

        ExtentSparkReporter sparkReporter = new ExtentSparkReporter(reportHtmlFilePath);
        JsonFormatter jsonFormatter = new JsonFormatter(reportJsonFilePath);

        sparkReporter.config().setProtocol(Protocol.HTTPS);
        sparkReporter.config().setEncoding("utf-8");
        sparkReporter.config().setTheme(Theme.DARK);
        sparkReporter.config().setTimeStampFormat("dd-MMM-yyyy HH:mm z");
        sparkReporter.config().setDocumentTitle(testClassName);
        sparkReporter.config().setReportName(testClassName);
        //sparkReporter.config().setTimelineEnabled(false);

        List <ViewName> displayOrder = Arrays.asList(ViewName.DASHBOARD, ViewName.TEST, ViewName.EXCEPTION, ViewName.CATEGORY, ViewName.DEVICE, ViewName.AUTHOR);
        sparkReporter.viewConfigurer().viewOrder().as(displayOrder).apply();

        extentReport.createDomainFromJsonArchive(reportJsonFilePath);
        extentReport.attachReporter(jsonFormatter, sparkReporter);

        extentTest = extentReport.createTest(testMethodName," ").assignCategory(testCategory).assignAuthor(author).assignDevice(Computer.COMPUTER_NAME);

But as I notices, Gson also can't parse date starting with month "Aug", as I can tell from a cause of this exception (Caused by: java.lang.NumberFormatException: Invalid number: Aug):

com.google.gson.JsonSyntaxException: Failed parsing 'Aug 24, 2023, 10:31:10?AM' as Date; at path $[0].startTime at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:90) at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:75) at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:46) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.readIntoField(ReflectiveTypeAdapterFactory.java:212) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:433) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:393) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61) at com.google.gson.Gson.fromJson(Gson.java:1227) at com.google.gson.Gson.fromJson(Gson.java:1137) at com.google.gson.Gson.fromJson(Gson.java:1047) at com.google.gson.Gson.fromJson(Gson.java:1014) at com.aventstack.extentreports.append.JsonDeserializer.deserialize(JsonDeserializer.java:30) at com.aventstack.extentreports.append.RawEntityConverter.convertAndApply(RawEntityConverter.java:27) at com.aventstack.extentreports.AbstractProcessor.convertRawEntities(AbstractProcessor.java:108) at com.aventstack.extentreports.ExtentReports.createDomainFromJsonArchive(ExtentReports.java:372) at com.aventstack.extentreports.ExtentReports.createDomainFromJsonArchive(ExtentReports.java:387) at com.cat.autotest.core.report.ReportWriter.start(ReportWriter.java:139) at com.cat.autotest.core.report.TestLogger.start(TestLogger.java:71)

Caused by: java.text.ParseException: Failed to parse date ["Aug 24, 2023, 10:31:10?AM"]: Invalid number: Aug at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:279) at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:88) ... 65 more Caused by: java.lang.NumberFormatException: Invalid number: Aug at com.google.gson.internal.bind.util.ISO8601Utils.parseInt(ISO8601Utils.java:316) at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:133) ... 66 more

What would be your suggestion for those 2 problems (not sure if independent) ? Thank you.