Created
April 16, 2011 03:10
-
-
Save taichi/922826 to your computer and use it in GitHub Desktop.
example code for Jackson 1.7.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import org.codehaus.jackson.JsonEncoding; | |
import org.codehaus.jackson.JsonFactory; | |
import org.codehaus.jackson.JsonGenerator; | |
import org.codehaus.jackson.map.ObjectMapper; | |
import org.codehaus.jackson.node.ArrayNode; | |
import org.codehaus.jackson.node.ObjectNode; | |
public class JacksonSample { | |
public static void main(String[] args) throws IOException { | |
JsonFactory factory = new JsonFactory(); | |
ObjectMapper om = new ObjectMapper(factory); | |
factory.setCodec(om); | |
ObjectNode node = om.createObjectNode(); | |
node.put("hoge", 1); | |
ObjectNode child = om.createObjectNode(); | |
child.put("piro", "10"); | |
ArrayNode an = om.createArrayNode(); | |
an.add(1); | |
an.add(2); | |
child.put("ary", an); | |
node.put("fuga", child); | |
JsonGenerator gen = factory.createJsonGenerator(System.out, | |
JsonEncoding.UTF8); | |
gen.writeTree(node); | |
gen.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment