0

Ok, so I am just getting into advanced topics like reflection in Java for an OOPrograming class at my university and am finding myself in deep water (for me anyway). We were given an assignment that requires writing a method like

public String serialize(Object o, Class<?> writeAs)

which takes an Object o and serializes it using Class writeAs as the most derived type in the type hierarchy of Object o to use for serializing it. The function needs to handle various Object types (primitives as well) and return a string with the proper JSON representation (boolean/string/number/array/object/null), thus serializing it in JSON. Not allowed to use anything like Gson etc... If the object is a Java array or Collection, the writeAs being its runtime class.

If a Java object is seen by serialize, all the public things need to be read and all their getters need to be ignored, save for the private and protected fields they reveal. There are a bunch more rules but I basically just need some help getting started on this.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Wes Field
  • 3,291
  • 6
  • 23
  • 26

0 Answers0