0

How can I calculate how much heap memory is needed to serialize a json object which is 5 mb of text?

I am using the fasterxml.jackson library in kotlin if that matters

Chicowitz
  • 5,759
  • 5
  • 32
  • 38
  • It's not clear what you ask. Do you mean how much heap memory it will use that code? – LMC Jul 24 '19 at 17:13

1 Answers1

0

This question is to broad and mostly depends from data types you chose for properties in POJO classes. For example, consider you have ten int properties or ten BigInteger properties, you can choose for date Calendar type or long, and so on. If file size is 5mb, I assume, it should contain some list of objects inside. In that case, you can create small JSON file with, for example, 100 objects and measure size in runtime. You can calculate average size for each type of POJO and multiply it by number of items in JSON file of given type. And formula could look like below:

enter image description here

Where:

  1. t - number of different POJO types.
  2. ai - average size of i-th POJO object in runtime.
  3. ni - number of i-th POJO objects after deserialisation.

See:

  1. Calculate size of Object in Java
  2. How to Get the Size of an Object in Java
Michał Ziober
  • 37,175
  • 18
  • 99
  • 146