I have a form in which I have some input in which when filling in with js I pick them up and add them to a hidden input that I have on the page.
document.editRouteForm.itinerary.value = itiToObj();
document.editRouteForm.itinerary.value = JSON.stringify(itiToObj());
The first one adds this information to me in the field:
And the second this:
Once it arrives at the controller it gives me a bug the BindingResult that tells me the following (this is if I do JSON.stringfy):
org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'route' on field 'itinerary': rejected value [{"name":"ch","color":"chjjhfd","salidasEntradas":["1","2","3"]}]; codes [typeMismatch.route.itinerary,typeMismatch.itinerary,typeMismatch.es.ticnor.trayecbus.model.Itinerary,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [route.itinerary,itinerary]; arguments []; default message [itinerary]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'es.ticnor.trayecbus.model.Itinerary' for property 'itinerary'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'es.ticnor.trayecbus.model.Itinerary' for property 'itinerary': no matching editors or conversion strategy found]
(this if I return the object):
Field error in object 'route' on field 'itinerary': rejected value [[object Object]]; codes [typeMismatch.route.itinerary,typeMismatch.itinerary,typeMismatch.es.ticnor.trayecbus.model.Itinerary,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [route.itinerary,itinerary]; arguments []; default message [itinerary]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'es.ticnor.trayecbus.model.Itinerary' for property 'itinerary'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'es.ticnor.trayecbus.model.Itinerary' for property 'itinerary': no matching editors or conversion strategy found]
Then with this error I make sure that the information arrives at the backend but is not able to process it.
This is the object I'm working with:
public class Itinerary implements Serializable {
private String name;
private String[] salidasEntradas;
private String color;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String[] getSalidasEntradas() {
return salidasEntradas;
}
public void setSalidasEntradas(String[] salidasEntradas) {
this.salidasEntradas = salidasEntradas;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Override
public String toString() {
return "Itinerary{" + "name=" + name + ", salidasEntradas=" + salidasEntradas + ", color=" + color + '}';
}
}