-
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
TypeConverter not used for inserting/updating type Object #79
Comments
Ugh. I tried working on a patch for this, but deep down in Micronaut Core is a check that makes this a non-trivial change: I can't fully figure out why there is that check for Object.class and while I get that it's technically true (a request to convert anything to Object arguably should just be a no-op), that line of code means for sure my TypeConverter that is taking an object and converting it to a PgObject (for Postgres JSONB support) will never get invoked. |
Thanks, will have a look, in the meantime do you have an example entity with what you are trying to achieve? Thanks |
I can provide a sample hello-world app, but it's not 100% self-contained like my other examples because H2 doesn't support JSON types. So if you want to run it, you'd need to set up a Postgres DB. But I don't think that is necessary. What I'm doing is straightforward: I have an |
It is ok if it is not self contained. We have tests that run against progress using test containers |
Here you go. The schema file is in |
Thanks, I will take a look soon, probably tomorrow... |
Thanks. It's not a huge rush. My first workaround bumped into the issues described in #80, but my workaround to the workaround is to just for the last generated ID. It's an extra query but it works. |
I didn't complete the work since it doesn't work in all different databases but for Postgres I did get support for Which uses |
Closing since we have native JSON support now |
I have the similar issue when use a List of JsonType, e.g.
Query and Create are ok. but got error when update this field to postgres DB: The column index is out of range
UserList is just a wrapper:
Hope this can help anyone has the same issue. |
Thanks @zearic for the tip. I still have the issue storing Map in JSONB column and have to use the workaround. |
TypeConverters are working wonderfully for reading/querying and writing/inserting/updating data except for one case: when you're trying to insert/update and expect a value to be converted before being bound to the statement.
You can see in this code where the problem is:
micronaut-data/data-runtime/src/main/java/io/micronaut/data/runtime/mapper/QueryStatement.java
Line 40 in 23075f0
All other data types have a nice callout to
convertRequired
except for the Object. This means my TypeConvert doesn't get utilized, resulting in a JDBC error. The specific use case is I'm trying to convert into JSONB type in Postgres. Interestingly, it works on queries because the code doesn't even try to understand the underlying type, it simply passes all ResultSet values off to the type converters:micronaut-data/data-runtime/src/main/java/io/micronaut/data/runtime/mapper/sql/SqlResultEntityTypeMapper.java
Line 229 in 23075f0
I'll see if I can get you a patch soon!
The text was updated successfully, but these errors were encountered: