HTML form submit not working with Spring Boot 2.3.1

Viewed 528

Entity conversion upon form submit for my specific case is not working anymore after switching from Spring Boot 2.2.7 to Spring Boot 2.3.1

Category.java

@Entity @Getter @Setter
public class Category implements Serializable {
    private Integer id;
    private String name;
}

SearchForm.java:

@Getter @Setter
public class SearchForm implements Serializable {
    private String q;
    private Category c;
}

HTML form:

<form method="get" th:action="@{/}" th:object="${searchForm}">
    <input th:field="*{q}" type="text" />
    <select th:field="*{c}">
        <option th:each="cat : ${categories}" th:value="${cat.id}"  th:text="${cat.name}" />
    </select>
</form>

Controller.java:

@PostMapping
public String post( @ModelAttribute final SearchForm searchForm ) {
    // ...
}

Previously with Spring Boot 2.2.7 form submit would convert "c" from HTML form (select is holding ID of Category) to Category entity in SearchForm.java

After switching to Spring Boot 2.3.1 this is not working anymore. An error is displayed in log instead:

Field error in object 'searchForm' on field 'c': rejected value [424]; codes [typeMismatch.searchForm.c,typeMismatch.c,typeMismatch.com.thevegcat.app.category.Category,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [searchForm.c,c]; arguments []; default message [c]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'com.thevegcat.app.category.Category' for property 'c'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.thevegcat.app.category.Category' for property 'c': no matching editors or conversion strategy found]]

1 Answers
Related