use of org.jdbi.v3.json.JsonMapper in project jdbi by jdbi.
the class JsonColumnMapperFactory method build.
@Override
public Optional<ColumnMapper<?>> build(Type type, ConfigRegistry config) {
ColumnMappers cm = config.get(ColumnMappers.class);
// look for specialized json support first, revert to simple String mapping if absent
ColumnMapper<String> jsonStringMapper = JdbiOptionals.findFirstPresent(() -> cm.findFor(QualifiedType.of(String.class).with(EncodedJson.class)), () -> cm.findFor(String.class)).orElseThrow(() -> new UnableToProduceResultException(JSON_NOT_RETRIEVABLE));
final JsonMapper mapper = config.get(JsonConfig.class).getJsonMapper();
return Optional.of((rs, i, ctx) -> mapper.fromJson(type, Optional.ofNullable(jsonStringMapper.map(rs, i, ctx)).orElse(// sql null -> json null
"null"), config));
}
Aggregations