1

I'm trying to understand if there's a limit to how much JSON the Spring framework will deserialize into an object.

My REST service receives POST requests where the body is a JSON string. This is automatically deserialized into an object by the Spring framework (3.2.5) and the object is provided as a method argument. One of the object's properties is an array. I want to provide some guidance in my documentation about the maximum number of array elements that a caller can include in an object.

I know that the .NET framework has a configurable limit on the size of a JSON string but I don't know of anything similar in Spring. My development server is currently churning away on a request with 100,000 elements (roughly 8,000,000 characters) and it hasn't blown up yet.

Any thoughts much appreciated!

tomfumb
  • 3,669
  • 3
  • 34
  • 50

1 Answers1

1

This depends on many things, including

  • Any specific limits imposed by your underlying JSON deserialization. Most likely you're using Jackson which has no limits I'm aware of
  • Container specific limits, you've not mentioned what container you're using, but for example Tomcat has a maxPostSize.
  • Front end web server limits, assuming for example tomcat behind apache. Apache has a LimitRequestBody property.
  • Memory, specifically heap size to parse the String into objects
  • Time, the edge case that the deserialize takes so long that the HTTP request times out with the client.

The most likely limit you'll hit first is the container specific one. I'd recommend using container/front proxy configuration to set sensible limits to protect yourself from bad clients.

Community
  • 1
  • 1
Adam
  • 35,919
  • 9
  • 100
  • 137
  • thanks this is definitely useful. However despite the fact that I *am* using Tomcat I don't see any reference to maxPostSize in any configuration files and I am able to POST over 7MB. I'll keep searching... – tomfumb Mar 03 '15 at 18:02