// I have a wrapper class like:
public class classWrapper {
    public A A_ITEMS;
    public B B_ITEMS;
    public C C_ITEMS;

public class C {
    public List<CItem> item;

public class CItem {
    public String P;
    public String F;
    public String B;
    public String A;
    public String T;               

I want to create an event of this class like:

List<classWrapper.CItem> cIList = new List<classWrapper.CItem>();
classWrapper.CItem cI = new classWrapper.CItem();
cI.P = '1';
cI.F = '2';
cI.B = '3';
cI.A = '10';
cI.T = '7';
C_ITEMS.item = cIList;

Similarly for other two items of class then i want to convert this result in JSON string.

My issue is I want result in JSON string should be in same order as public String P;

              "T":"7" ]}}

but I am getting result as:


i.e. fields are getting sorted but I want them to be remain in same order as written in class definition.

  • 1
    JSON property order is strictly irrelevant since you can deserialize and access them directly by name. It's also not something you can control as covered in this question if you use JSON.serialize. Why is order important for you?
    – Phil W
    Apr 8, 2022 at 7:36

1 Answer 1


You can deserialize and then manipulate the data. As long as all the data is returned, there shouldn't be any issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .