Created
July 24, 2012 23:45
-
-
Save hgschmie/3173456 to your computer and use it in GitHub Desktop.
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
public class Jacksonian | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
final JsonFactory jf = new JsonFactory(); | |
final ObjectMapper mapper = new ObjectMapper(); | |
final JsonParser jp; | |
if(args.length > 0) { | |
jp = jf.createJsonParser(new File(args[0])); | |
} | |
else { | |
jp = jf.createJsonParser(System.in); | |
} | |
final Writer wr; | |
if (args.length > 1) { | |
wr = new FileWriter(new File(args[1])); | |
} | |
else { | |
wr = new OutputStreamWriter(System.out); | |
} | |
Preconditions.checkState(jp.nextToken() == JsonToken.START_ARRAY); | |
while (jp.nextToken() != JsonToken.END_ARRAY) { | |
final JsonNode jn = mapper.readTree(jp); | |
final JsonGenerator jg = jf.createJsonGenerator(wr); | |
mapper.writeTree(jg, jn); | |
wr.append("\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment