Skip to content

Instantly share code, notes, and snippets.

@shinsaka
Created September 19, 2017 03:35
Show Gist options
  • Save shinsaka/bbbbb693ff24ba368e17605e18adbd8f to your computer and use it in GitHub Desktop.
Save shinsaka/bbbbb693ff24ba368e17605e18adbd8f to your computer and use it in GitHub Desktop.
using JSONGenerator with Apex/SFDC
Hoge p = new Hoge();
p.code = '0001';
p.name = 'hogename1';
p.items = new List<HogeItem>{
new HogeItem('0001-01', 'item001'),
new HogeItem('0001-02', 'item002')
};
JSONGenerator jg = JSON.createGenerator(false);
jg.writeObject(p);
System.debug(jg.getAsString());
public class Hoge {
public String code;
public String name;
public List<HogeItem> items;
}
public class HogeItem {
public String itemcode;
public String itemname;
public HogeItem(String code, String name) {
this.itemcode = code;
this.itemname = name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment