Skip to content

Unwrapped fields cannot be resolved in the constructor  #4491

Closed
@kakao-rick-lee

Description

@kakao-rick-lee

I am designing a domain object using @unwrapped, but the constructor fails to resolve the Unwrapped Field (age).

public class Age {
    private int age;

    public Age(int age) {
        this.age = age;
    }
}
@Document("mydoc")
public class MyDoc {

    @Id
    private String id;
    private String name;

    @Unwrapped.Empty
    private Age age;

    @PersistenceCreator
    public MyDoc(String id, String name, Age age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }
}

Error Message

No converter found capable of converting from type [java.lang.Integer] to type [com.company.test.mongotest.model.Age]

I've checked with @Vaule and SpEl that it's possible to use the code below, but I don't think it's a good idea. Is there any way to automatically resolve unwrapped fields in the constructor?

public class MyDoc {

    // omitted

    @PersistenceCreator
    public MyDoc(String id, String name, @Value("new com.company.test.mongotest.model.Age(age)") Age age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions