I realized ObjectMapper's writeValueAsString
method takes an Object
type as a parameter. But it is able to produce correct JSON from underlying class object(which is a subclass of Object class
). Normally, Java compiler wouldn't be able to access fields of a subclass from a superclass. How does ObjectMapper do it?
Asked
Active
Viewed 22 times
0

nmd_07
- 666
- 1
- 9
- 25
-
4Probably by using reflection. – Henry Oct 12 '20 at 14:07
-
Via Reflection? Object.getClass returns subclass... So you can iterate fields – Selvin Oct 12 '20 at 14:07