This question is about software design, not "code", and so is off-topic: try asking on our sister site softwareengineering.stackexchange.com. That said, read/write your objects as json using jackson library - it will handle everything for you. — Bohemian ♦ 42 secs ago