java - Sorting class fileds while conversion it to json using Gson -


i create class json representation:

class myclass {     public long a;     public string c;     public string b;      @override     public tostring(){         return new gsonbuilder().create().tojson(this)     } } 

i use it:

myclass c = new myclass(); c.a = 10; c.b = "b"; c.c = "c"; string json = c.tostring(); 

i have json next:

{"c":"c","b":"b", "a":10} 

but want have:

{"a":10, "b":"b", "c":"c"} 

how can sort field in json? (using gson or other methods)

in real project have more complex structure inheritance , lists of other objects.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -