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

fails to encode string to varchar due to precedence of JsonCodec over StringCodec #195

Open
dragneelfps opened this issue Jun 24, 2021 · 0 comments

Comments

@dragneelfps
Copy link

Bug Report

Versions

  • Driver: 0.9.0.BUILD-SNAPSHOT
  • Database: h2
  • Java: 11
  • OS: Win10

Current Behavior

JsonCodec tries to encode/decode for non-json string values and fails with exception.

This is because JsonCodec and StringCodec both have supported type as String, and JsonCodec is before StringCodec in the codec list. It throws exception at https://github.com/r2dbc/r2dbc-h2/blob/main/src/main/java/io/r2dbc/h2/codecs/DefaultCodecs.java#L68-L72

Expected behavior/code

It should not use JsonCodec in case the value is not a JSON-string.

Possible Solution

Solution 1

Override

public boolean canEncode(Object value) {
in JsonCodec and check if the string is a json serialized string or not

Cons:

  • it does not take into account when the someone is storing json serialized string as varchar.
@dragneelfps dragneelfps changed the title fails to encode varchar(in database) into string(in entity class) due to JsonCodec fails to encode string to varchar due to precedence of JsonCodec over StringCodec Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant