Jackson deserialization max depth level





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















With Spring Boot application I post JSON with 10000 nested elements, like the one below and got java.lang.StackOverflowError.



{
"__id": "1",
"__category":{
"key1": {
"key2": {
"key3": {
...
...
"key10000": "value"
...
...
}
}
}
}
}


Is there any way to make this error more manageable?



I mean, I don't want avoid this error, but do something like custom deserializer to set a value of nesting allowed and throw some exception if this value exceeded.










share|improve this question































    0















    With Spring Boot application I post JSON with 10000 nested elements, like the one below and got java.lang.StackOverflowError.



    {
    "__id": "1",
    "__category":{
    "key1": {
    "key2": {
    "key3": {
    ...
    ...
    "key10000": "value"
    ...
    ...
    }
    }
    }
    }
    }


    Is there any way to make this error more manageable?



    I mean, I don't want avoid this error, but do something like custom deserializer to set a value of nesting allowed and throw some exception if this value exceeded.










    share|improve this question



























      0












      0








      0








      With Spring Boot application I post JSON with 10000 nested elements, like the one below and got java.lang.StackOverflowError.



      {
      "__id": "1",
      "__category":{
      "key1": {
      "key2": {
      "key3": {
      ...
      ...
      "key10000": "value"
      ...
      ...
      }
      }
      }
      }
      }


      Is there any way to make this error more manageable?



      I mean, I don't want avoid this error, but do something like custom deserializer to set a value of nesting allowed and throw some exception if this value exceeded.










      share|improve this question
















      With Spring Boot application I post JSON with 10000 nested elements, like the one below and got java.lang.StackOverflowError.



      {
      "__id": "1",
      "__category":{
      "key1": {
      "key2": {
      "key3": {
      ...
      ...
      "key10000": "value"
      ...
      ...
      }
      }
      }
      }
      }


      Is there any way to make this error more manageable?



      I mean, I don't want avoid this error, but do something like custom deserializer to set a value of nesting allowed and throw some exception if this value exceeded.







      java json spring serialization jackson






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 11:03







      Andrew

















      asked Nov 16 '18 at 17:46









      AndrewAndrew

      7811




      7811
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You could try using the Jackson Streaming API instead of having to deserialize the whole thing at once. That's the recommended approach when dealing with a large JSON object or array.



          This allows you to deserialize and process components individually without needing the entire JSON object to exist in memory.






          share|improve this answer
























          • As I understand, the main point of my problem is a big number of recursive calls. I catch java.lang.StackOverflowError during recursive call of com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject() method. So if I use Jackson Streaming API, I will catch the same error because of very big depth of my JSON's nesting.

            – Andrew
            Nov 19 '18 at 18:57













          • @Andrew With the streaming API you should be able to work with iteration instead of recursion which should substantially reduce the memory footprint. You might need a state machine if the input is fairly complex.

            – Baldy
            Nov 20 '18 at 17:00












          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',
          autoActivateHeartbeat: false,
          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%2f53342936%2fjackson-deserialization-max-depth-level%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









          0














          You could try using the Jackson Streaming API instead of having to deserialize the whole thing at once. That's the recommended approach when dealing with a large JSON object or array.



          This allows you to deserialize and process components individually without needing the entire JSON object to exist in memory.






          share|improve this answer
























          • As I understand, the main point of my problem is a big number of recursive calls. I catch java.lang.StackOverflowError during recursive call of com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject() method. So if I use Jackson Streaming API, I will catch the same error because of very big depth of my JSON's nesting.

            – Andrew
            Nov 19 '18 at 18:57













          • @Andrew With the streaming API you should be able to work with iteration instead of recursion which should substantially reduce the memory footprint. You might need a state machine if the input is fairly complex.

            – Baldy
            Nov 20 '18 at 17:00
















          0














          You could try using the Jackson Streaming API instead of having to deserialize the whole thing at once. That's the recommended approach when dealing with a large JSON object or array.



          This allows you to deserialize and process components individually without needing the entire JSON object to exist in memory.






          share|improve this answer
























          • As I understand, the main point of my problem is a big number of recursive calls. I catch java.lang.StackOverflowError during recursive call of com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject() method. So if I use Jackson Streaming API, I will catch the same error because of very big depth of my JSON's nesting.

            – Andrew
            Nov 19 '18 at 18:57













          • @Andrew With the streaming API you should be able to work with iteration instead of recursion which should substantially reduce the memory footprint. You might need a state machine if the input is fairly complex.

            – Baldy
            Nov 20 '18 at 17:00














          0












          0








          0







          You could try using the Jackson Streaming API instead of having to deserialize the whole thing at once. That's the recommended approach when dealing with a large JSON object or array.



          This allows you to deserialize and process components individually without needing the entire JSON object to exist in memory.






          share|improve this answer













          You could try using the Jackson Streaming API instead of having to deserialize the whole thing at once. That's the recommended approach when dealing with a large JSON object or array.



          This allows you to deserialize and process components individually without needing the entire JSON object to exist in memory.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 22:14









          BaldyBaldy

          1,8651114




          1,8651114













          • As I understand, the main point of my problem is a big number of recursive calls. I catch java.lang.StackOverflowError during recursive call of com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject() method. So if I use Jackson Streaming API, I will catch the same error because of very big depth of my JSON's nesting.

            – Andrew
            Nov 19 '18 at 18:57













          • @Andrew With the streaming API you should be able to work with iteration instead of recursion which should substantially reduce the memory footprint. You might need a state machine if the input is fairly complex.

            – Baldy
            Nov 20 '18 at 17:00



















          • As I understand, the main point of my problem is a big number of recursive calls. I catch java.lang.StackOverflowError during recursive call of com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject() method. So if I use Jackson Streaming API, I will catch the same error because of very big depth of my JSON's nesting.

            – Andrew
            Nov 19 '18 at 18:57













          • @Andrew With the streaming API you should be able to work with iteration instead of recursion which should substantially reduce the memory footprint. You might need a state machine if the input is fairly complex.

            – Baldy
            Nov 20 '18 at 17:00

















          As I understand, the main point of my problem is a big number of recursive calls. I catch java.lang.StackOverflowError during recursive call of com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject() method. So if I use Jackson Streaming API, I will catch the same error because of very big depth of my JSON's nesting.

          – Andrew
          Nov 19 '18 at 18:57







          As I understand, the main point of my problem is a big number of recursive calls. I catch java.lang.StackOverflowError during recursive call of com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject() method. So if I use Jackson Streaming API, I will catch the same error because of very big depth of my JSON's nesting.

          – Andrew
          Nov 19 '18 at 18:57















          @Andrew With the streaming API you should be able to work with iteration instead of recursion which should substantially reduce the memory footprint. You might need a state machine if the input is fairly complex.

          – Baldy
          Nov 20 '18 at 17:00





          @Andrew With the streaming API you should be able to work with iteration instead of recursion which should substantially reduce the memory footprint. You might need a state machine if the input is fairly complex.

          – Baldy
          Nov 20 '18 at 17:00




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53342936%2fjackson-deserialization-max-depth-level%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

          The Sandy Post

          Danny Elfman

          Pages that link to "Head v. Amoskeag Manufacturing Co."