I have a form on a web page to which I collect some values from JS and add them to an object. All those objects I put them into an array and add it to a hidden input I have on the page:
document.editRouteForm.busStops.value = JSON.stringify(getBusStopsPoints());
var getBusStopsPoints = function () {
var arrayPos = 0;
busStops.map(function (marker) {
//Recogemos las rutas
busStopsObj.lat = marker.getPosition().lat();
busStopsObj.lng = marker.getPosition().lng();
//Recogemos la descripcion
busStopsObj.description = busStopsInfo[arrayPos];
arrayPos++;
console.log("arrayPos: " + arrayPos);
busStopsForm.push(busStopsObj);
});
console.log(busStopsForm);
};
The output I get is the following:
[
{
"lat":43.4721537946863,
"lng":-3.8495182526509097,
"description":"2"
},
{
"lat":43.4721537946863,
"lng":-3.8495182526509097,
"description":"2"
},
{
"lat":43.4721537946863,
"lng":-3.8495182526509097,
"description":"2"
}
]
Now on the server it comes to me as null and it gives me an exception:
[Field error in object 'route' on field 'busStops': rejected value [undefined]; codes [typeMismatch.route.busStops, typeMismatch.busStops, typeMismatch.java.util.List, typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [route.busStops, busStops]; arguments []; default message [busStops]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'busStops'; nested exception is java.lang.IllegalStateException: Can not convert value of type 'java.lang.String' to required type 'en.ticnor.trayecbus.model.BusStop' for property 'busStops [0]': no matching editors or conversion strategy found]]
I am trying to add the values of an object in the back-end with the data that comes from the front. One of those values is a List < > of another object. Which is where the server gives me the exception.
private final List<BusStop> busStops = new ArrayList<>();
And the object is formed by these fields: public class BusStop extends BaseEntity {
private String description;
private float lat;
private float lng;
The form works and the parameters arrive to him except that field that apparently does not correspond with the expected (an ArrayList of objets). So someone knows why I get this fault? Maybe the output I get from the form with the expected one on the server does not correspond?
Greetings and thanks in advance.