MapStruct
Java
Property Mapping
Source `Parameters`
Code Generation

MAPSTRUCT. No property named packaging exists in source parameters

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The MapStruct error "No property named packaging exists in source parameter(s)" means the source path in a @Mapping annotation does not match what the mapper method actually receives. In practice, the fix is usually to point MapStruct at the correct parameter path, or stop mapping a field that does not exist on the source side.

Why the Error Happens

MapStruct resolves source values against the parameters of the mapping method. If the method has one source parameter, MapStruct can often infer the root object. If the method has multiple parameters, the path must usually start with the parameter name.

This mapper is a common source of the error:

java
1@Mapper
2public interface ProductMapper {
3
4    @Mapping(target = "packaging", source = "packaging")
5    ProductDto toDto(Product product, Category category);
6}

If neither top-level parameter is named or structured so that packaging is directly resolvable, MapStruct reports that it cannot find such a source property.

Use the Full Parameter Path

If packaging lives on product, name that explicitly:

java
1import org.mapstruct.Mapper;
2import org.mapstruct.Mapping;
3
4@Mapper
5public interface ProductMapper {
6
7    @Mapping(target = "packaging", source = "product.packaging")
8    ProductDto toDto(Product product, Category category);
9}

Now MapStruct knows that packaging should be read from the product parameter rather than from some ambiguous top-level source.

This is especially important any time a mapping method has more than one source parameter.

Check the Actual Java Bean Properties

MapStruct works with Java bean accessors, not field names in isolation. So even if a class contains a field named packaging, the generated mapper expects a readable property such as:

java
public String getPackaging() {
    return packaging;
}

If the getter is missing, non-standard, or generated incorrectly by Lombok configuration, MapStruct may behave as though the property does not exist.

That means the debugging checklist is:

  • verify the mapper method parameter names
  • verify the property path
  • verify the getter exists with bean naming conventions

Ignore or Compute the Target Field Instead

Sometimes the target has a packaging field, but the source does not. In that case, the right fix is not to force a source path that does not exist. Either ignore the target field:

java
1@Mapper
2public interface ProductMapper {
3
4    @Mapping(target = "packaging", ignore = true)
5    ProductDto toDto(Product product);
6}

or compute it with an expression or helper method:

java
1@Mapper
2public interface ProductMapper {
3
4    @Mapping(target = "packaging", expression = "java(product.isFragile() ? \"BOX\" : \"NONE\")")
5    ProductDto toDto(Product product);
6}

This makes the mapper intention explicit instead of pretending a missing source property exists.

Read the Error Literally

MapStruct compile errors are often more precise than they first appear. "No property named packaging exists in source parameter(s)" does not mean MapStruct is broken. It usually means the annotation describes a source path that the mapper signature cannot satisfy.

When you read the method signature and the @Mapping lines together, the fix is usually obvious.

Common Pitfalls

  • Writing source = "packaging" in a mapper with multiple source parameters when the real path is product.packaging.
  • Assuming a field is enough even though MapStruct relies on bean-style getters and setters.
  • Trying to map a target property from a source property that does not exist.
  • Ignoring parameter names in the mapper signature when building source paths.
  • Using source when the correct answer is actually ignore = true or a computed expression.

Summary

  • This MapStruct error means the source path does not match the mapper method inputs.
  • In multi-parameter mappings, include the parameter name in the source path.
  • Confirm that the source object exposes the property through standard bean accessors.
  • Ignore or compute the target field if no real source property exists.
  • The fix is usually in the annotation path, not in MapStruct itself.

Course illustration
Course illustration

All Rights Reserved.