Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

https://gerrit.onap.org/r/c/cps/+/123682 we had to introduce a 'new' ObjectMapper to resolve issues with datatypes. The question now is if we should update the same ObjectMapper everywhere in the project or even across all CPS projects.

Object Mapper

Jackson

Jackson is tailored towards parsing larger files. According to cited benchmarks it is slower than GSON with large files and much slower with small files.

Although Jackson is slower in parsing in all use cases, we have a specific use case in which Jackson parser excels due to its ability to acknowledge the data type which it is parsing. For example in CpsDataPersistenceImpl.java in the toDataNode method, we use the Jackson Object mapper to parse fragment entity attributes to a map of objects. CPS-591 implemented a bug fix to change the parser from GSON to Jackson as GSON was reading integer values as Doubles https://gerrit.onap.org/r/c/cps/+/123682

It is also widely known as the most popular JSON parsing library.

GSON

GSON is faster than Jackson mapper. However, as mentioned in the use case above, GSON is not capable of parsing well when it does not know the data type which it is mapping. It is possible to cast the incoming data to the correct datatype but it is not useful in the case where we do not know the incoming datatype. As such, in the use case mentioned above it is more practical to use the Jackson parser.

Legacy Code

The cited article also shows benchmarks from 2017 in which Jackson parser was out performing GSON in the large file category. We can surmise that there is a constant battle between these objectMappers and Jackson may begin out performing GSON again in the future. For example this article from 2019 with new benchmarks states that the difference between the different mappers is negligible, with Jackson mapper having a slight lead with larger files.

Resolution

It would make the most sense to use GSON as much as possible as it is the faster than Jackson. However the practicality of Jacksons parsing cannot be overlooked. Therefore it would make sense to use the Jackson parser in this scenario. We also don't want to have or create a Jackson mapper and GSON mapper object in the same file however as the memory cost is quite high.

  • GSON parser should solely be used in a class where possible.
  • In the case where the Jackson mapper is necessary, the Jackson mapper should be used in the whole class so that there is only one parser object created for a class

CPS-NCMP

Temporal


  • No labels