How to change serialization order when dealing with inheritance?

1,476 views
Skip to first unread message

Alexander Muravya

unread,
Oct 28, 2013, 7:59:01 AM10/28/13
to googl...@googlegroups.com
Hello all!

I am quite happy using GSON and its default serializer.

Here my inheritance structure:

public class Reply{
   private int code;
}

public class ConcreteReply extends Reply{
  private String concreteStr;
}

By default it serialized into following JSON
{ "concreteStr":"value", "code":0 }

Firstly fields of child object and then super object

How to reverse this order?

In this example I want to achieve  following result: 

{ "code":0, "concreteStr":"value" }

Hemal Pandya

unread,
Jan 27, 2014, 8:57:55 PM1/27/14
to googl...@googlegroups.com
I asked almost the exact same question on stackoverflow -- see http://stackoverflow.com/questions/21151189/serialize-sub-class-after-super-class.

I got the elements-are-unordered objections that I had sort of expected but no love for my argument that support staff would really appreciate being able to see it in a predictable order without having to write a tool just to view some json logged in log files.

Did you manage to find anything usefule?
Reply all
Reply to author
Forward
0 new messages