Skip to content

inserting null values fails #6

@hagaic

Description

@hagaic

When extending AbstractMapping, if the propertyGetter function returns null then map... fails with NPE.
For example, mapDecimal() suggested fix:

    protected void mapDecimal(String columnName, int precision, int scale, Func2<TEntity, BigDecimal> propertyGetter)
    {
        // We need to scale the incoming decimal, before writing it to SQL Server:
        final Func2<TEntity, BigDecimal> wrapper = entity -> {

            BigDecimal result = Optional.ofNullable(propertyGetter
                    .invoke(entity))
                    .map(d -> d.setScale(scale, BigDecimal.ROUND_HALF_UP))
                    .orElse(null);

            return result;
        };

        addColumn(columnName, Types.DECIMAL, precision, scale, false, wrapper);
    }

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions