0

The following client code

FormData formData = FormData(document.getElementById(formElemId));
formData.append('version', null);

when received in Server Side via Spring MVC as below

@RequestParam(value = 'version', required = false) Integer versionNumber

throws the following exception

Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "null"

1 Answer 1

0

You can resolve this issue by adding defaultValue like below.

@RequestParam(value = "version", required = false, defaultValue = "0") Integer versionNumber

see documentation

Sign up to request clarification or add additional context in comments.

5 Comments

Unfortunately I cannot set a default value to the version (Application Logic). I'll have to handle the null in client itself. So I was wondering what turns my null object in client to string null when received in server.
actually it was a bug in previous versions which has been resolved now...try with latest versions defaultValue is not needed.
Oh thanks for that. Can you please let me know on which version is this bug was fixed. Am currently on 4.3.9
This was considered a bug in 2013: jira.spring.io/browse/SPR-10180 and was fixed with version 3.2.2. Problem shouldn't occur in any versions after that and your code should work just fine.
With the latest spring boot, if I use @ModelAttribute, this exception still exist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.