Skip to content

Instantly share code, notes, and snippets.

@ecerulm
Created August 2, 2010 19:52
Show Gist options
  • Save ecerulm/505206 to your computer and use it in GitHub Desktop.
Save ecerulm/505206 to your computer and use it in GitHub Desktop.
// to generate the following JSON output
// {"identifier":"abbreviation",
// "items":[ {"name":"Alaska","label":"Alaska","abbreviation":"AK"},
// {"name":"Wyoming","label":"Wyoming","abbreviation":"WY"}
// ]}
package com.rubenlaguna.json.flexjson;
import flexjson.JSONSerializer;
public class WriteFlexjsonDojoTest {
public static void main(String[] args) {
ItemCollection itemCollection = new ItemCollection("abbreviation");
itemCollection.add(new Item("Alaska", "Alaska", "AK"));
itemCollection.add(new Item("Wyoming", "Wyoming", "WY"));
JSONSerializer serializer = new JSONSerializer().include("items").exclude("*.class");
String correctJsonStr = serializer.serialize(itemCollection);
System.out.println(correctJsonStr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment