Given: Invoice and InvoiceItem as JPA entities. InvoiceItem has property invoice with type Invoice.
Calling /invoice/addItem?invoice=1
did bind the invoice with the given id to InvoiceItem.invoice
with Spring Boot 2.3.0 and 2.2.7.
Since the update to 2.3.1 or 2.2.8 the following error occurs:
2020-06-25 11:50:19.824 WARN 98947 --- [ Test worker] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'invoiceItem' on field 'invoice': rejected value [1]; codes [typeMismatch.invoiceItem.invoice,typeMismatch.invoice,typeMismatch.ch.itds.demo.mvcbindingissue.domain.Invoice,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [invoiceItem.invoice,invoice]; arguments []; default message [invoice]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'ch.itds.demo.mvcbindingissue.domain.Invoice' for property 'invoice'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'ch.itds.demo.mvcbindingissue.domain.Invoice' for property 'invoice': no matching editors or conversion strategy found]]
Example project: https://github.com/itds-ch/spring-boot-mvc-binding-issue
I created the branches spring-boot-2.3.0
and spring-boot-2.3.1
to simplify the verification. The only difference of these branches is the spring boot version.
Comment From: wilkinsona
Thanks for the sample. The problem's caused by a regression in Spring Data's converter registration. It's been fixed in the latest snapshots so the tests in your sample will pass with these changes:
diff --git a/build.gradle b/build.gradle
index 4d5d550..4937418 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,8 +8,11 @@ group = 'ch.itds.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '14'
+ext['spring-data-releasetrain.version'] = 'Neumann-BUILD-SNAPSHOT'
+
repositories {
mavenCentral()
+ maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
Alternatively, you could downgrade to Neumann-RELEASE
:
diff --git a/build.gradle b/build.gradle
index 4d5d550..7388261 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,6 +8,8 @@ group = 'ch.itds.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '14'
+ext['spring-data-releasetrain.version'] = 'Neumann-RELEASE'
+
repositories {
mavenCentral()
}
We'll pick up the fix which will be in Spring Data Neumann-SR2 in due course.
Comment From: mkobel
Thank you for your rapid response. The suggested change works for me.