JOOQ+杰克逊由于案例敏感性而无法将JSON转换为Pojo
以下代码失败:
final var account = dc.select(ACCOUNT.asterisk())
.from(ACCOUNT)
.limit(1)
.forJSON().path().withoutArrayWrapper()
.fetchOneInto(Account.class);
错误消息就像:
由: com.fasterxml.jackson.databind.exc.unrecognized propertyexception: 未识别的字段“ firstName” ...已知属性:...“ firstName” ...
杰克逊似乎遇到问题,将上案例列的第一名映射到Pojo的小写字段“ firstName”(并且在所有其他字段中相似)。我正在使用生成的类。在仍在使用JSON的同时,该如何修复?
JOOQ版本为3.16,数据库为Oracle。
The following code fails:
final var account = dc.select(ACCOUNT.asterisk())
.from(ACCOUNT)
.limit(1)
.forJSON().path().withoutArrayWrapper()
.fetchOneInto(Account.class);
The error message is like:
Caused by:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "FIRSTNAME" ... known properties: ... "firstname"
...
Jackson seems to have problems mapping the upper case column FIRSTNAME into the pojo's lowercase field "firstname" (and similar for all other fields). I am using the generated classes. How can I fix it while still using json?
The jooq version is 3.16 and the database is oracle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将杰克逊映射用例固定
在您的特定查询中,您可以将所有列自动添加到其较低的情况相等的列,例如:
完全避免使用用例,
但是,考虑到您的特定查询通过JSON序列化,只能从第三方映射器中受益。为什么也不使用JOOQ来做到这一点?
或者,如果
帐户
是不变的类(例如Java记录),为什么不使用类型的安全映射:Fixing the Jackson mapping use-case
In your particular query, you could auto-alias all columns to their lower case equivalent, e.g.:
Avoiding the use-case entirely
However, given your particular query, I don't really see the point of passing through the JSON serialisation only to benefit from a third party mapper. Why not use jOOQ for that as well?
Or, if
Account
is an immutable class (e.g. a Java record), why not use type safe mapping like this: