github-actions[bot] commented on issue #12983: URL: https://github.com/apache/dolphinscheduler/issues/12983#issuecomment-1325870613
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues. ### What happened https://github.com/apache/dolphinscheduler/blob/dev/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/json/DateJsonSerializer.java When converting Date to String, the input parameter is java.util.Date, and then the date.toInstant() method will be called internally to convert it to LocalDateTime. However, there is a problem here: in the internal implementation of jdk, java.sql.Date is inherited from java.util.Date, but the toInstant() method is not implemented, resulting in a direct error when calling. jdk method source code: /** * This method always throws an UnsupportedOperationException and should * not be used because SQL {@code Date} values do not have a time * component. * * @exception java.lang.UnsupportedOperationException if this method is invoked */ @Override public Instant toInstant() { throw new java.lang.UnsupportedOperationException(); } ### What you expected to happen The following code provides an idea to convert sql.Date to util.Date: @JsonComponent public class DateJsonSerializer extends JsonSerializer<Date> { @Override public void serialize(Date value, JsonGenerator gen, SerializerProvider serializers) throws IOException { Date temp = value; // In the internal implementation of JDK, sql.Date is inherited from util.Date, and sql.Date has rewritten many methods in util.Date, but it has not been implemented. // Later, when formatting, you need to call the method in Date to report an error. if (value instanceof java.sql.Date) { Calendar calendar = Calendar. getInstance(); calendar. setTime(value); temp = calendar. getTime(); } gen.writeString(DateUtils.dateToString(temp)); } } ### How to reproduce Enter java.sql.Date to reproduce ### Anything else _No response_ ### Version dev ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
