2022-07-21

ajax, upload file, json string, Spring Controller, DTO

 



Googled: json to dto spring boot controller




Resolved by follow the example on: 

Spring Boot controller - Upload Multipart and JSON to DTO




thread solution at: https://stackoverflow.com/a/49993072


Ajax Javascript
formData.append( 'dtoName', new Blob([JSON.stringify(dtoJavascriptObject)], {
type: "application/json"
}));

Spring Controller parameter

@RequestPart ManualGenerateCsv dtoName






couldn't parse json attribute to java object attribute.

 







private boolean isRequiredFtpToSSS;

public void setRequiredFtpToSSS(boolean isRequiredFtpToSSS) {
this.isRequiredFtpToSSS = isRequiredFtpToSSS;
}

Since your attribute name: isRequiredFtpToSSS
Due to jackson is expecting: setIsRequiredFtpToSSS
But there has no "is for the auto generated setter: setRequiredFtpToSSS





So u have to add this.

@JsonProperty("isRequiredFtpToSSS")
private boolean isRequiredFtpToSSS;


















Jackson JSON parsing from string to date.

 









@JsonFormat(pattern = "yyyy-MMM-dd")
private Date dateFrom;





not sure if were causing by:
MethodArgumentConversionNotSupportedException when I try to map json string onto java domain class in Spring controller's method






jquery 3.3.1 change checkbox checked

 







Found: 
Make checkbox value checked with jQuery or JavaScript
but seems not the same case.



the one i'm using.

$("#chkHasDateTo").prop('checked', dto.hasDateTo);



But i remember there are more elegant way to do the same thing....

Jquery Datepicker: click on a checkbox, then open/pop datepicker of a textbox.

 


click on a checkbox, then open/pop datepicker of a textbox.



if($("#chkHasDateTo").is(":checked")){
$( "#dateTo" ).trigger( "select" );
$( "#dateTo" ).trigger( "focus" );
}

















Google Referrals