-
Notifications
You must be signed in to change notification settings - Fork 195
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
SQL Wraps JSON in Quotes for Postgres JSON/JSONB Column types - Breaks Postgres Json Features. #672
Comments
Also, this may conflict the fix for #482 |
@mphouston what's your workaround? |
My work around is on github (see block on workAround672). I have a sub-class of the DefaultJdbcRepositoryOperations that adds some features. The work around is to clear the jsonCodec value. That causes it to revert back to just plain string storage. (I know, the work-around is an ugly hack :). There might be a way to get the DefaultJdbcRepositoryOperations bean and just clear that in your code. |
Sadly, that's not possible in Kotlin or atleast i couldn't find a way to modify jsonCodec to null from child class |
Did you try it with reflection like I did? I don't know Kotlin well, but I think standard Java could get could access the private field with this kind of kludge (not exact syntax, but close enough, I hope) :
It would be ugly, but good enough for the short term. There might be some other, better way to clear the codec, but I could not find it. I assume the Micronaut team will make some other option available in the future... |
Will someone be working on this? Or at least can someone give me guidance on how to fix this? |
Will be looking at data issues next week and catching up, PRs welcome in the meantime. Sorry for the delay. |
Thanks a lot, I've tried to do it by myself but the complexity kills me, after 2 days I still hadn't got idea how and why everything works under the hood and I thought that it's better to leave it to others than fix it by brute force changing. Thanks and have a good day. |
(Awesome work on Micronaut and Micronaut-Data. We really love it :).
When saving a string field to a Postgres JSON/JSONB column, Micronaut-Data wraps the string in quotes. This prevents the Postgres engine from parsing the value and prevents us from using the Postgres JSON SQL extensions.
This also returns the quotes value on the next read, so we can't parse the JSON using Jackson either.
BTW, I have a workaround, so this is not urgent.
This issue is fixed simplistically by setting the DefaultJdbcRepositoryOperations.jsonCodec to null. Other solutions might be possible. I amusing UTF-8 strings, so there might be some problems with this solution...
Steps to Reproduce
Expected Behaviour
The JSON is accesible by Postgres SQL extension (e.g. fields->'color'='Blue'). And retrieving the string returns the exact string saved.
Actual Behaviour
The JSON string is saved with with enclosing quotes. This prevents Postgres from parsing this and using it a JSON object.
Also, the string value returned is changed to: "{\"color\": \"Blue\"}".
Environment Information
Example Application
Example app: https://github.com/mphouston/mn-issues/tree/master/ref-issue
Run: ./gradlew test
The test JsonColumnIssueTest is the one that demonstrates this issue.
The text was updated successfully, but these errors were encountered: