Require some insight regarding Objects & Json
Bernd Eckenfels
ecki at zusammenkunft.net
Sun Nov 12 21:17:42 UTC 2017
Hello,
the Java Objects will occupy more (especially If the Parser does not provide a way to merge same-string-content objects.
It depends on the Parser what is converted (but I am not Aware of any which Support Enumerations out of the box, especially since JSON-P JSR is limited to generic (DOM-like) objects)
I also think the list here is a bit offtopic for such a question, what JSON-Parser do you plan to use?
Gruss
Bernd
--
http://bernd.eckenfels.net
Von: Prakhar Makhija
Gesendet: Sonntag, 12. November 2017 18:57
An: core-libs-dev at openjdk.java.net; core-libs-dev-request at openjdk.java.net
Betreff: Require some insight regarding Objects & Json
Hi,
*Scenario*
Having 1.5 million json files of same structure (same keys).
Each file is of around 64 KB, which makes a total of 1 GB.
Created a class MyDummyJsonClass, having the attribute names same as the
keys in those json files.
Reading the json files, loading them into MyDummyJsonClass, using
ObjectMapper.
*Doubt 1*
Will the objects occupy the same amount of space in Java's Memory, as they
were occupying earlier as flat files?
*Doubt 2*
Does Java convert Objects to Enumerations at Runtime?
What I mean to ask is, does it enumerate the attribute names while creating
objects, in order to save the memory?
Because the Class is just a blueprint, and we create objects out of it over
and over again.
*Example*
class MyDummyJsonClass {
private Object meaningfulNameOfAttributeOne;
private String meaningfulNameOfAttributeTwo;
private Integer meaningfulNameOfAttributeThree;
private Float meaningfulNameOfAttributeFour;
private Double meaningfulNameOfAttributeFive;
private Long meaningfulNameOfAttributeSix;
private Byte meaningfulNameOfAttributeSeven;
private Boolean meaningfulNameOfAttributeEight;
private Character meaningfulNameOfAttributeNine;
private Short meaningfulNameOfAttributeTen;
// Contructors
// Getters & Setters
}
Here the field meaningfulNameOfAttributeOne is of 28 characters, and Java
uses Unicode, so internally just this attribute name will it be occupying
56 bytes of memory in every Object we create?
Or is meaningfulNameOfAttributeOne mapped to enum value 1, and will occupy
maybe just 1 byte, depending upon the number of fields?
If less than or equal to 256 fields in the class, allocate 1 byte enum,
else 2 bytes enum.
And some kind of Interceptor decides, to give it logical attribute name
mapping?
More information about the core-libs-dev
mailing list