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

java.sql.Time throws java.lang.UnsupportedOperationException when serialized. #655

Open
rogeriosorroche opened this issue Nov 18, 2024 · 0 comments
Labels
bug Something isn't working right

Comments

@rogeriosorroche
Copy link

rogeriosorroche commented Nov 18, 2024

Describe the bug
java.sql.Time throws java.lang.UnsupportedOperationException when serialized because org.eclipse.yasson.internal.serializer.types.DateSerializer tries to convert the object to a java.time.Instant, using method java.sql.Time.toInstant(). For type java.sql.Date this issue was handled in the class org.eclipse.yasson.internal.serializer.types.SqlDateSerializer. The same aproach may be used to java.sql.Time.

To Reproduce
Create a class with a java.sql.Time field:

public class MyBean {

     private java.sql.Time time;

    public java.sql.Time getTime() {
          return time;
    }

    public void setTime(java.sql.Time time) {
          this.time = time;
    }

}

// Try to serialize this bean.

MyBean value = new MyBean();
value.setTime(java.sql.Time.valueOf("10:00:00"));

Jsonb jsonb = JsonbBuilder.newBuilder().build();
String str = jsonb.toJson(value);

Expected behavior
Must serialize correctly, but throws UnsupportedOperationException:

Caused by: java.lang.UnsupportedOperationException
at java.sql/java.sql.Time.toInstant(Time.java:281)
at org.eclipse.yasson@3.0.4/org.eclipse.yasson.internal.serializer.types.DateSerializer.toInstant(DateSerializer.java:36)
at org.eclipse.yasson@3.0.4/org.eclipse.yasson.internal.serializer.types.SqlDateSerializer.toInstant(SqlDateSerializer.java:36)
at org.eclipse.yasson@3.0.4/org.eclipse.yasson.internal.serializer.types.DateSerializer.formatDefault(DateSerializer.java:41)
at org.eclipse.yasson@3.0.4/org.eclipse.yasson.internal.serializer.types.SqlDateSerializer.formatDefault(SqlDateSerializer.java:45)
at org.eclipse.yasson@3.0.4/org.eclipse.yasson.internal.serializer.types.SqlDateSerializer.formatDefault(SqlDateSerializer.java:23)
....

System information:

  • OS: any
  • Java Version: >= 8
  • Yasson Version: 3.0.4
@rogeriosorroche rogeriosorroche added the bug Something isn't working right label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

No branches or pull requests

1 participant