I want to serialize a complex Java object throw Internet. First time, I used Google Gson to serialize the class. Gson offers an easy way to serialize object into JSON string and deserialize from JSON string to object via toJson and fromJson. However, JSON string is not so compact and introduce large overhead when serialize byte[] array.
I am reading Google Protocol Buffer. According to the tutorial, Users have to write .proto file for each message manually. It seems to that Protocol Buffer could not recognize user-defined-class (Google protocol buffers - user defined java objects as messages fields). I have 2 questions:
- Does protocol buffer know built-in Java-defined class such as BigDecimal, BigInteger,…?
- If we have a complex class which recursively has other user-defined classes as members, do we need to travel all classes’ definition and declare them as message which their filed in .proto file? If so, It is very terrible for user (and maybe they use some external java library and do not have source code of defined classes in that library)
Is there a tool to automatically traverse the Java class and generate .proto?