Skip to content

Bug: Mapper Generation Fails for List<Integer> Fields #4

@wassertim

Description

@wassertim

Bug: Mapper Generation Fails for List Fields

Problem Description

The DynamoDB Toolkit annotation processor fails to generate valid mapper code when a @DynamoMappable class contains a List<Integer> field. The generated mapper attempts to use a non-existent ListMapper class, causing compilation failure.

Error Message

[ERROR] /workspace/apps/backend/target/generated-sources/annotations/com/github/wassertim/dynamodb/toolkit/mappers/RouteInstructionMapper.java:[22,19] cannot find symbol
[ERROR]   symbol:   class ListMapper
[ERROR]   location: class com.github.wassertim.dynamodb.toolkit.mappers.RouteInstructionMapper

Affected Domain Class

package com.tourino.domain;

import com.github.wassertim.dynamodb.toolkit.api.annotations.DynamoMappable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@DynamoMappable
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class RouteInstruction {
    private String text;
    private Double distance;
    private Double duration;
    private String type;
    
    // This field causes the generation error
    private List<Integer> waypointIndices;
}

Generated Mapper Code (Problematic)

@ApplicationScoped
public class RouteInstructionMapper {
    private final ListMapper listMapper;  // ❌ ListMapper doesn't exist

    public RouteInstructionMapper(ListMapper listMapper) {
        this.listMapper = listMapper;
    }

    public AttributeValue toDynamoDbAttributeValue(RouteInstruction routeInstruction) {
        // ...
        if (routeInstruction.getWaypointIndices() != null) {
            AttributeValue waypointIndicesValue = listMapper.toDynamoDbAttributeValue(routeInstruction.getWaypointIndices());
            if (waypointIndicesValue != null) {
                attributes.put("waypointIndices", waypointIndicesValue);
            }
        }
        // ...
    }
}

Expected Behavior

The generator should handle primitive wrapper lists (List<Integer>, List<Long>, List<String>, etc.) by generating code that directly converts them to DynamoDB's number/string list format, similar to how it handles simple types.

Suggested Fix

For List<Integer> and other primitive wrapper lists, the generator should create code like:

if (routeInstruction.getWaypointIndices() != null) {
    List<AttributeValue> list = routeInstruction.getWaypointIndices().stream()
        .map(val -> AttributeValue.builder().n(String.valueOf(val)).build())
        .collect(Collectors.toList());
    attributes.put("waypointIndices", AttributeValue.builder().l(list).build());
}

Workaround

Current workaround is to exclude this field from DynamoDB mapping or handle it manually, but this defeats the purpose of the annotation processor.

Environment

  • DynamoDB Toolkit version: v1.1.0
  • Java version: 21
  • Build tool: Maven

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions