JsonBinaryType doesn't support String Object without quotes
See original GitHub issueUsing
hibernate-types-52
2.9.12 with PostgreSQL
I would like to be able to persist an arbitrary Object
member in my entity using JSONB …
CREATE TABLE my_entity (
id BIGSERIAL PRIMARY KEY,
data JSONB,
);
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
public class MyEntity {
@Type(type = "jsonb")
@Column(columnDefinition = "json")
private Object data;
// Getters and setters removed for brevity
}
This works fine for the following cases …
myEntity.setData(List.of("hello"));
myEntity.setData(Map.of("hello", "world"));
myEntity.setData(null);
myEntity.setData(5);
But not for …
myEntity.setData("hello");
JsonParseException
is thrown by the call to objectMapper.readTree(…) because instances of String
do not get wrapped in quotes
I believe the fix here is to simply remove the instanceof
conditional …
else if (Object.class.isAssignableFrom(type)) {
return (X) objectMapperWrapper.toJsonNode(toString(value));
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Switch from JsonStringType to JsonBinaryType when the ...
It works fine with String column data type but I get an error with JsonNode as you show above - "Unable to build...
Read more >Unquoting JSON strings; print JSON strings without quotes
This answer is probably preferable since the escaping is probably not limited to adding quotation marks, but also escapes quotation marks in the ......
Read more >How to read a JSON string without field name quotes in Jackson
We often have to read JSON values where the field names are not quoted, i.e., when enclosed with double ( "" ) or...
Read more >How to map JSON objects using generic Hibernate Types
MySQL 5.7 adds support for JSON types, which, at the JDBC level, ... Not only that JSON Object(s) are properly transformed from their ......
Read more >Which is better to use, json/jsonb or string to store ... - Quora
There are a few factors. That you mention it is not frequently used then you may want to go with json. The JSON...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m not discarding this request since JSON is also used to save unvalidated data, hence it should be less strict.
I created the following branch on GitHub. The persist works fine. It’s just that the unwrapping needs to discard the quotes. I’ll have to find a way to fix that. If you have time, you could take a look and see whether there’s a clever way to address it.
@michaelcowan There are lots of test failures. It’s not as simple as just removing that check. You have to remember that these types have to work on Oracle, SQL Server, PostgreSQL, and MySQL.