Tak jak w tytule..
Mam sobie takie DTO
public class MainSearchFilterDTO {
public final boolean ascending;
public final boolean withPhotos;
public final boolean withMapPoint;
public MainSearchFilterDTO(@JsonProperty(value = "ascending") boolean ascending,
@JsonProperty(value = "withPhotos") boolean withPhotos,
@JsonProperty(value = "withMapPoint") boolean withMapPoint){
this.ascending = ascending;
this.withPhotos = withPhotos;
this.withMapPoint = withMapPoint;
}
i taką metodę controllera
@RequestMapping(value = "/searchresults", method = POST)
public Set<Resource<SearchResultDTO>> getFilteredSearchResults(MainSearchFilterDTO mainSearchFilterDTO) {
return mainSearchService.getAdvertsByFilter(mainSearchFilterDTO);
}
ze strony angulara wysyłam posta z jsonem przetworzonym z DTO
export class MainSearchFilterDTO2 {
private _ascending: boolean;
private _withPhotos: boolean;
private _withMapPoint: boolean;
set ascending(value: boolean) {
this._ascending = value;
}
get withPhotos(): boolean {
return this._withPhotos;
}
set withPhotos(value: boolean) {
this._withPhotos = value;
}
get withMapPoint(): boolean {
return this._withMapPoint;
}
set withMapPoint(value: boolean) {
this._withMapPoint = value;
}
public toJSON() {
return {
ascending: this._ascending,
withPhotos: this._withPhotos,
withMapPoint: this._withMapPoint
};
}
}
JSON:
{
"ascending":true,
"withPhotos":true,
"withMapPoint":false
}
I spring odbija mi request:
detailed msg:
"Failed to convert value of type 'null' to required type 'boolean'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [@com.fasterxml.jackson.annotation.JsonProperty boolean] for value 'null'; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type"
Pytanie.. wtf? W czym jest błąd?