JavaScript: Formdata append null value - NumberFormatException











up vote
0
down vote

favorite












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"










share|improve this question


























    up vote
    0
    down vote

    favorite












    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"










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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"










      share|improve this question













      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"







      javascript ajax spring-mvc form-data






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 10:35









      Mohan Krishnan

      508




      508
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          You can resolve this issue by adding defaultValue like below.



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


          see documentation






          share|improve this answer





















          • 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.
            – Mohan Krishnan
            Nov 8 at 13:58










          • actually it was a bug in previous versions which has been resolved now...try with latest versions defaultValue is not needed.
            – Alien
            Nov 8 at 14:01










          • Oh thanks for that. Can you please let me know on which version is this bug was fixed. Am currently on 4.3.9
            – Mohan Krishnan
            Nov 8 at 14:08






          • 1




            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.
            – Alien
            Nov 8 at 14:18











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205938%2fjavascript-formdata-append-null-value-numberformatexception%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          You can resolve this issue by adding defaultValue like below.



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


          see documentation






          share|improve this answer





















          • 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.
            – Mohan Krishnan
            Nov 8 at 13:58










          • actually it was a bug in previous versions which has been resolved now...try with latest versions defaultValue is not needed.
            – Alien
            Nov 8 at 14:01










          • Oh thanks for that. Can you please let me know on which version is this bug was fixed. Am currently on 4.3.9
            – Mohan Krishnan
            Nov 8 at 14:08






          • 1




            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.
            – Alien
            Nov 8 at 14:18















          up vote
          0
          down vote



          accepted










          You can resolve this issue by adding defaultValue like below.



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


          see documentation






          share|improve this answer





















          • 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.
            – Mohan Krishnan
            Nov 8 at 13:58










          • actually it was a bug in previous versions which has been resolved now...try with latest versions defaultValue is not needed.
            – Alien
            Nov 8 at 14:01










          • Oh thanks for that. Can you please let me know on which version is this bug was fixed. Am currently on 4.3.9
            – Mohan Krishnan
            Nov 8 at 14:08






          • 1




            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.
            – Alien
            Nov 8 at 14:18













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          You can resolve this issue by adding defaultValue like below.



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


          see documentation






          share|improve this answer












          You can resolve this issue by adding defaultValue like below.



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


          see documentation







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 8 at 10:52









          Alien

          3,60621022




          3,60621022












          • 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.
            – Mohan Krishnan
            Nov 8 at 13:58










          • actually it was a bug in previous versions which has been resolved now...try with latest versions defaultValue is not needed.
            – Alien
            Nov 8 at 14:01










          • Oh thanks for that. Can you please let me know on which version is this bug was fixed. Am currently on 4.3.9
            – Mohan Krishnan
            Nov 8 at 14:08






          • 1




            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.
            – Alien
            Nov 8 at 14:18


















          • 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.
            – Mohan Krishnan
            Nov 8 at 13:58










          • actually it was a bug in previous versions which has been resolved now...try with latest versions defaultValue is not needed.
            – Alien
            Nov 8 at 14:01










          • Oh thanks for that. Can you please let me know on which version is this bug was fixed. Am currently on 4.3.9
            – Mohan Krishnan
            Nov 8 at 14:08






          • 1




            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.
            – Alien
            Nov 8 at 14:18
















          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.
          – Mohan Krishnan
          Nov 8 at 13:58




          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.
          – Mohan Krishnan
          Nov 8 at 13:58












          actually it was a bug in previous versions which has been resolved now...try with latest versions defaultValue is not needed.
          – Alien
          Nov 8 at 14:01




          actually it was a bug in previous versions which has been resolved now...try with latest versions defaultValue is not needed.
          – Alien
          Nov 8 at 14:01












          Oh thanks for that. Can you please let me know on which version is this bug was fixed. Am currently on 4.3.9
          – Mohan Krishnan
          Nov 8 at 14:08




          Oh thanks for that. Can you please let me know on which version is this bug was fixed. Am currently on 4.3.9
          – Mohan Krishnan
          Nov 8 at 14:08




          1




          1




          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.
          – Alien
          Nov 8 at 14:18




          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.
          – Alien
          Nov 8 at 14:18


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205938%2fjavascript-formdata-append-null-value-numberformatexception%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Schultheiß

          Liste der Kulturdenkmale in Wilsdruff

          Android Play Services Check