Open Isax03 opened 4 months ago
This looks like missing mappers. We did not provide set of mappers for primitive types in DB client. They are implemented in tests, but maybe we should expose them as part of default mappers.
Unfortunately there is always some grey area in number conversion which needs to be defined somehow.
null
value as source will throw an NPEvalue > 0
rule to return true
. Values null
, 0
and negative values are considered as false
true -> 1
and false -> 0
Please can you verify that https://github.com/Tomas-Kraus/helidon/tree/issue-9062 build fixes your issue?
I'm sorry but these days I can't. Btw, you can easily reproduce the bug.
I never touched Kotlin so I can work only on Java side and verify that test implemented in Java works. This was done as part of the PR:
boolean
attribute. Statements and mapping tests were updated to work with it.private static final class PokemonMapper implements DbMapper<Pokemon> {
@Override
public Pokemon read(DbRow row) {
return new Pokemon(row.column("id").get(Integer.class),
row.column("name").get(String.class),
row.column("healthy").get(Boolean.class));
}
...
}
public record Pokemon(int id, String name, boolean healthy, List<Type> types) {
public Pokemon(int id, String name, boolean healthy, Type... types) {
this(id, name, healthy, List.of(types));
}
public Pokemon(int id, String name, Type... types) {
this(id, name, true, types);
}
...
}
But as you can see, it's the same as your Kotlin code.
I did not see any problem with the mappers I added. Also Postgres test was working fine even without boolean mappers in Java environment. The only database that required mappers was Oracle.
So it sounds quite strange, that custom mapper did not work. Mapper framework is being used for a long time and should be reliable. Were you able to reproduce it in pure Java environment too?
Environment Details
Problem Description
In the implementation of a
DbMapper
for an entity following the Entity Pattern, we encountered an issue when mapping boolean values from a PostgreSQL database. Specifically, the error arises when attempting to map PostgreSQL boolean types tojava.lang.Boolean
in Kotlin. The mapper is designed to extract various columns from a database row, including several boolean fields.Here is a simplified version of the code causing the issue:
The relevant portion of the error message is:
This issue consistently occurs when mapping boolean fields from the database. The expectation was that the boolean fields in the database, represented as
boolean
in PostgreSQL, would be seamlessly mapped tojava.lang.Boolean
in the application layer. However, the error indicates that the mapping infrastructure does not have a predefined mapper for this conversion, resulting in aMapperException
.Steps to Reproduce
DbMapper
for an entity, including boolean fields, using Helidon DB Client.java.lang.Boolean
in Kotlin.java.lang.Boolean
.This issue is reproducible consistently under the described conditions.
Questions