1
class Bean
{
    private String x,y,z,a,b,c;
    //Getters & Setters
}

Using struts2 json plugin, the json that gets generated for the above bean is in Lexicographical order

This [reference], says that since JDK 6 it is supported in declaration order, but in JSON response, I see the fields arranged in lexicographic order.

Is there any way to achieve declaration order in the generated JSON ?

Community
  • 1
  • 1
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
  • I did this... but I forget how at the moment (not at home computer) but I do remember that I asked a question to do with this (on here). If I recall it was using the java compiler API or a related API and reflection, using that you can figure out the line number of the declarations (or anything else really), and use that for conventions. Which makes a lot more sense than using annotations. You'll need a custom JSON result too! – Quaternion Nov 25 '13 at 23:10
  • http://stackoverflow.com/questions/3148274/java-get-declared-methods-in-order-they-apear-in-source-code & http://stackoverflow.com/questions/12834887/how-to-get-the-line-number-of-a-method/14973713#comment21272750_14973713 - They suggest to write my own json plugin. – coding_idiot Nov 26 '13 at 05:46
  • One of them also suggests that it works for declaration order in JDK 6, but I'm using 7 and it's not like that. – coding_idiot Nov 26 '13 at 05:49
  • Right Javassist should do mostly what you need, but the declarations need to be on separate lines (if going by declaration, otherwise your code could determine order by getter/setter if that proves to be ambiguous. (as it would be in your case)) – Quaternion Nov 27 '13 at 20:16

0 Answers0