I'm working on a project where we have to deal with a number of JSON entities and an SDK to make calls for that JSONs. To map JSON to DTO we use the Jackson library and TypeReference class.
Let's say there is a Repository do deal with a certain type of JSONs and there are methods that use new TypeReference under that hood.
class Repository {
a() {
new TypeReference<MyDto> {}
}
b() {
new TypeReference<MyDto> {}
}
}
It would create next classes after build:
Repository$1.class
Repository$2.class
Basically, I have 2 global questions :
Would the number of declarations of the same TypeReference affect somehow my project? Because there would be generated .class files for each declaration. Would it affect a classloader?
Would you suggest any best practices to deal with TypeReference? Should I put them into a dedicated util class? Should it be a singleton instance of TypeReference or it doesn't make any sense to have it as a singleton?
Move to util class to prevent over-creating of .class files.