Harshit
Harshit

Reputation: 1263

Java : Is it possible to deserialize objects without reflection

My understanding is that deserializing any object uses reflection underneath, always, no matter what be the case.

Heard somebody advocating the contrary.

Please help out in validating this understands ng. Is there any such technique in Java (or any other language) which does not depends upon reflection.

Edit : No opinions are being asked here on the preference of any approach. This is simply to be aware about any possible approach exists or not ??

Upvotes: 2

Views: 1244

Answers (1)

Nicktar
Nicktar

Reputation: 5575

Basically there are two ways to deserialize objects (from JSON, from the database or even from Javas own Serialization).

The one nearly everyone is using relies on reflection to learn about the structure of the Object to create and to populate the structure.

The other way creates factories for the objects it needs to desirialize during build phase. For this it creates a lot of classes and has to know at build time which objects it will need to deserialize. The only framework I know of that follows this path is micronaut.

Even if you provide reflectionless methods to populate your objects (this can be done), we still need reflection to find and call these methods.

Upvotes: 4

Related Questions