Failed To Convert Property Value Of Type 'java.lang.String'

- 1 answer

What am I doing wrong here?

<select th:field="*{role}">
    <option value="#" disabled="disabled" selected="selected">Role...</option>
    <option th:each="r : ${roles}" th:value="${r}" th:text="${}">Developer</option>

I am getting this error:

Field error in object 'collaborator' on field 'role': rejected value
[33]; codes
codes [collaborator.role,role]; arguments []; default message [role]];
default message [*Failed to convert property value of type
'java.lang.String' to required type
'com.imprender.instateam.model.Role' for property 'role'*; nested
exception is java.lang.IllegalStateException: Cannot convert value of
type 'java.lang.String' to required type
'com.imprender.instateam.model.Role' for property 'role': no matching
editors or conversion strategy found]

It says:

**Failed to convert property value of type 'java.lang.String' to required type 'com.imprender.instateam.model.Role' for property

but I don't understand where I am doing that.

I think I am not properly transmiting the value selected in the . I thought the object sent would be the one declared in the valueoption that gets selected, but obviously I got it wrong and can't find the way to do it properly.

The model:

package com.imprender.instateam.model;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

public class Collaborator {

    //Todo: check strategy
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Pattern(regexp = "([A-Z][a-zA-Z]*\\s*)+")
    private String name;

    //Todo: check, do we want to create a new table to associate values?

    private Role role;

    public Collaborator() {

    public Long getId() {
        return id;

    public void setId(Long id) { = id;

    public String getName() {
        return name;

    public void setName(String name) { = name;

    public Role getRole() {
        return role;

    public void setRole(Role role) {
        this.role = role;


Your problem is that in your select says the field is a role, entity type Role, but in your options the value is an ID, some primitive value, then doesnt match. You can change to this

<select th:field="*{}">
    <option value="#" disabled = "disabled" selected="selected">Role...</option>
    <option th:each="r : ${roles}" th:value="${}" th:text="${}">Developer</option>