Java Code Examples for org.codehaus.jackson.JsonFactory#createJsonGenerator()
The following examples show how to use
org.codehaus.jackson.JsonFactory#createJsonGenerator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatePool.java From hadoop with Apache License 2.0 | 6 votes |
private void write(DataOutput out) throws IOException { // This is just a JSON experiment System.out.println("Dumping the StatePool's in JSON format."); ObjectMapper outMapper = new ObjectMapper(); outMapper.configure( SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true); // define a module SimpleModule module = new SimpleModule("State Serializer", new Version(0, 1, 1, "FINAL")); // add the state serializer //module.addSerializer(State.class, new StateSerializer()); // register the module with the object-mapper outMapper.registerModule(module); JsonFactory outFactory = outMapper.getJsonFactory(); JsonGenerator jGen = outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8); jGen.useDefaultPrettyPrinter(); jGen.writeObject(this); jGen.close(); }
Example 2
Source File: Configuration.java From RDFS with Apache License 2.0 | 6 votes |
/** * Writes out all the parameters and their properties (final and resource) to * the given {@link Writer} * The format of the output would be * { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2, * key2.isFinal,key2.resource}... ] } * It does not output the parameters of the configuration object which is * loaded from an input stream. * @param out the Writer to write to * @throws IOException */ public static void dumpConfiguration(Configuration config, Writer out) throws IOException { JsonFactory dumpFactory = new JsonFactory(); JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out); dumpGenerator.writeStartObject(); dumpGenerator.writeFieldName("properties"); dumpGenerator.writeStartArray(); dumpGenerator.flush(); synchronized (config) { for (Map.Entry<Object,Object> item: config.getProps().entrySet()) { dumpGenerator.writeStartObject(); dumpGenerator.writeStringField("key", (String) item.getKey()); dumpGenerator.writeStringField("value", config.get((String) item.getKey())); dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey())); dumpGenerator.writeStringField("resource", config.updatingResource.get(item.getKey())); dumpGenerator.writeEndObject(); } } dumpGenerator.writeEndArray(); dumpGenerator.writeEndObject(); dumpGenerator.flush(); }
Example 3
Source File: AvroJson.java From brooklin with BSD 2-Clause "Simplified" License | 6 votes |
/** * Convert the HashMap {@code _info} into an AvroSchema * This involves using the Avro Parser which will ensure the entire * schema is properly formatted * * If the Schema is not formatted properly, this function will throw an * error */ public Schema toSchema() throws SchemaGenerationException { try { ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = new JsonFactory(); StringWriter writer = new StringWriter(); JsonGenerator jgen = factory.createJsonGenerator(writer); jgen.useDefaultPrettyPrinter(); mapper.writeValue(jgen, _info); String schema = writer.getBuffer().toString(); return Schema.parse(schema); } catch (IOException e) { throw new SchemaGenerationException("Failed to generate Schema from AvroJson", e); } }
Example 4
Source File: StatePool.java From big-c with Apache License 2.0 | 6 votes |
private void write(DataOutput out) throws IOException { // This is just a JSON experiment System.out.println("Dumping the StatePool's in JSON format."); ObjectMapper outMapper = new ObjectMapper(); outMapper.configure( SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true); // define a module SimpleModule module = new SimpleModule("State Serializer", new Version(0, 1, 1, "FINAL")); // add the state serializer //module.addSerializer(State.class, new StateSerializer()); // register the module with the object-mapper outMapper.registerModule(module); JsonFactory outFactory = outMapper.getJsonFactory(); JsonGenerator jGen = outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8); jGen.useDefaultPrettyPrinter(); jGen.writeObject(this); jGen.close(); }
Example 5
Source File: QueueManager.java From big-c with Apache License 2.0 | 5 votes |
/*** * Dumps the configuration of hierarchy of queues with * the xml file path given. It is to be used directly ONLY FOR TESTING. * @param out the writer object to which dump is written to. * @param configFile the filename of xml file * @throws IOException */ static void dumpConfiguration(Writer out, String configFile, Configuration conf) throws IOException { if (conf != null && conf.get(DeprecatedQueueConfigurationParser. MAPRED_QUEUE_NAMES_KEY) != null) { return; } JsonFactory dumpFactory = new JsonFactory(); JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out); QueueConfigurationParser parser; boolean aclsEnabled = false; if (conf != null) { aclsEnabled = conf.getBoolean(MRConfig.MR_ACLS_ENABLED, false); } if (configFile != null && !"".equals(configFile)) { parser = new QueueConfigurationParser(configFile, aclsEnabled); } else { parser = getQueueConfigurationParser(null, false, aclsEnabled); } dumpGenerator.writeStartObject(); dumpGenerator.writeFieldName("queues"); dumpGenerator.writeStartArray(); dumpConfiguration(dumpGenerator,parser.getRoot().getChildren()); dumpGenerator.writeEndArray(); dumpGenerator.writeEndObject(); dumpGenerator.flush(); }
Example 6
Source File: ServiceResponseBuilder.java From WSPerfLab with Apache License 2.0 | 5 votes |
public static ByteArrayOutputStream buildTestBResponse(JsonFactory jsonFactory, BackendResponse response) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(bos); jsonGenerator.writeStartObject(); // delay values of each response jsonGenerator.writeArrayFieldStart("delay"); writeTuple(jsonGenerator, "a", response.getDelay()); jsonGenerator.writeEndArray(); // itemSize values of each response jsonGenerator.writeArrayFieldStart("itemSize"); writeTuple(jsonGenerator, "a", response.getItemSize()); jsonGenerator.writeEndArray(); // numItems values of each response jsonGenerator.writeArrayFieldStart("numItems"); writeTuple(jsonGenerator, "a", response.getNumItems()); jsonGenerator.writeEndArray(); // all items from responses jsonGenerator.writeArrayFieldStart("items"); addItemsFromResponse(jsonGenerator, response); jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); jsonGenerator.close(); return bos; }
Example 7
Source File: WriteJsonResult.java From nifi with Apache License 2.0 | 5 votes |
public WriteJsonResult(final ComponentLog logger, final RecordSchema recordSchema, final SchemaAccessWriter schemaAccess, final OutputStream out, final boolean prettyPrint, final NullSuppression nullSuppression, final OutputGrouping outputGrouping, final String dateFormat, final String timeFormat, final String timestampFormat, final String mimeType) throws IOException { super(out); this.logger = logger; this.recordSchema = recordSchema; this.schemaAccess = schemaAccess; this.nullSuppression = nullSuppression; this.outputGrouping = outputGrouping; this.mimeType = mimeType; final DateFormat df = dateFormat == null ? null : DataTypeUtils.getDateFormat(dateFormat); final DateFormat tf = timeFormat == null ? null : DataTypeUtils.getDateFormat(timeFormat); final DateFormat tsf = timestampFormat == null ? null : DataTypeUtils.getDateFormat(timestampFormat); LAZY_DATE_FORMAT = () -> df; LAZY_TIME_FORMAT = () -> tf; LAZY_TIMESTAMP_FORMAT = () -> tsf; final JsonFactory factory = new JsonFactory(); factory.setCodec(objectMapper); this.generator = factory.createJsonGenerator(out); if (prettyPrint) { generator.useDefaultPrettyPrinter(); } else if (OutputGrouping.OUTPUT_ONELINE.equals(outputGrouping)) { // Use a minimal pretty printer with a newline object separator, will output one JSON object per line generator.setPrettyPrinter(new MinimalPrettyPrinter("\n")); } }
Example 8
Source File: TestHistograms.java From RDFS with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { final Configuration conf = new Configuration(); final FileSystem lfs = FileSystem.getLocal(conf); for (String arg : args) { Path filePath = new Path(arg).makeQualified(lfs); String fileName = filePath.getName(); if (fileName.startsWith("input")) { LoggedDiscreteCDF newResult = histogramFileToCDF(filePath, lfs); String testName = fileName.substring("input".length()); Path goldFilePath = new Path(filePath.getParent(), "gold"+testName); ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getJsonFactory(); FSDataOutputStream ostream = lfs.create(goldFilePath, true); JsonGenerator gen = factory.createJsonGenerator(ostream, JsonEncoding.UTF8); gen.useDefaultPrettyPrinter(); gen.writeObject(newResult); gen.close(); } else { System.err.println("Input file not started with \"input\". File "+fileName+" skipped."); } } }
Example 9
Source File: Configuration.java From flink with Apache License 2.0 | 5 votes |
/** * Writes out all the parameters and their properties (final and resource) to * the given {@link Writer} * The format of the output would be * { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2, * key2.isFinal,key2.resource}... ] } * It does not output the parameters of the configuration object which is * loaded from an input stream. * @param out the Writer to write to * @throws IOException */ public static void dumpConfiguration(Configuration config, Writer out) throws IOException { JsonFactory dumpFactory = new JsonFactory(); JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out); dumpGenerator.writeStartObject(); dumpGenerator.writeFieldName("properties"); dumpGenerator.writeStartArray(); dumpGenerator.flush(); synchronized (config) { for (Entry<Object,Object> item: config.getProps().entrySet()) { dumpGenerator.writeStartObject(); dumpGenerator.writeStringField("key", (String) item.getKey()); dumpGenerator.writeStringField("value", config.get((String) item.getKey())); dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey())); String[] resources = config.updatingResource.get(item.getKey()); String resource = UNKNOWN_RESOURCE; if(resources != null && resources.length > 0) { resource = resources[0]; } dumpGenerator.writeStringField("resource", resource); dumpGenerator.writeEndObject(); } } dumpGenerator.writeEndArray(); dumpGenerator.writeEndObject(); dumpGenerator.flush(); }
Example 10
Source File: Configuration.java From big-c with Apache License 2.0 | 5 votes |
/** * Writes out all the parameters and their properties (final and resource) to * the given {@link Writer} * The format of the output would be * { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2, * key2.isFinal,key2.resource}... ] } * It does not output the parameters of the configuration object which is * loaded from an input stream. * @param out the Writer to write to * @throws IOException */ public static void dumpConfiguration(Configuration config, Writer out) throws IOException { JsonFactory dumpFactory = new JsonFactory(); JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out); dumpGenerator.writeStartObject(); dumpGenerator.writeFieldName("properties"); dumpGenerator.writeStartArray(); dumpGenerator.flush(); synchronized (config) { for (Map.Entry<Object,Object> item: config.getProps().entrySet()) { dumpGenerator.writeStartObject(); dumpGenerator.writeStringField("key", (String) item.getKey()); dumpGenerator.writeStringField("value", config.get((String) item.getKey())); dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey())); String[] resources = config.updatingResource.get(item.getKey()); String resource = UNKNOWN_RESOURCE; if(resources != null && resources.length > 0) { resource = resources[0]; } dumpGenerator.writeStringField("resource", resource); dumpGenerator.writeEndObject(); } } dumpGenerator.writeEndArray(); dumpGenerator.writeEndObject(); dumpGenerator.flush(); }
Example 11
Source File: TestHistograms.java From big-c with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { final Configuration conf = new Configuration(); final FileSystem lfs = FileSystem.getLocal(conf); for (String arg : args) { Path filePath = new Path(arg).makeQualified(lfs); String fileName = filePath.getName(); if (fileName.startsWith("input")) { LoggedDiscreteCDF newResult = histogramFileToCDF(filePath, lfs); String testName = fileName.substring("input".length()); Path goldFilePath = new Path(filePath.getParent(), "gold"+testName); ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getJsonFactory(); FSDataOutputStream ostream = lfs.create(goldFilePath, true); JsonGenerator gen = factory.createJsonGenerator(ostream, JsonEncoding.UTF8); gen.useDefaultPrettyPrinter(); gen.writeObject(newResult); gen.close(); } else { System.err.println("Input file not started with \"input\". File "+fileName+" skipped."); } } }
Example 12
Source File: Configuration.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Writes out all the parameters and their properties (final and resource) to * the given {@link Writer} * The format of the output would be * { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2, * key2.isFinal,key2.resource}... ] } * It does not output the parameters of the configuration object which is * loaded from an input stream. * @param out the Writer to write to * @throws IOException */ public static void dumpConfiguration(Configuration config, Writer out) throws IOException { JsonFactory dumpFactory = new JsonFactory(); JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out); dumpGenerator.writeStartObject(); dumpGenerator.writeFieldName("properties"); dumpGenerator.writeStartArray(); dumpGenerator.flush(); synchronized (config) { for (Entry<Object,Object> item: config.getProps().entrySet()) { dumpGenerator.writeStartObject(); dumpGenerator.writeStringField("key", (String) item.getKey()); dumpGenerator.writeStringField("value", config.get((String) item.getKey())); dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey())); String[] resources = config.updatingResource.get(item.getKey()); String resource = UNKNOWN_RESOURCE; if(resources != null && resources.length > 0) { resource = resources[0]; } dumpGenerator.writeStringField("resource", resource); dumpGenerator.writeEndObject(); } } dumpGenerator.writeEndArray(); dumpGenerator.writeEndObject(); dumpGenerator.flush(); }
Example 13
Source File: CoTAdapterInbound.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
private void initializeJsonGenerator() throws IOException { try { factory = new JsonFactory(); jsonBuffer = new ByteArrayOutputStream(CAPACITY); generator = factory.createJsonGenerator(jsonBuffer); } catch (Exception e) { log.error(e); log.error(e.getStackTrace()); } }
Example 14
Source File: CoTAdapterInbound.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 5 votes |
private void initializeJsonGenerator() throws IOException { try { factory = new JsonFactory(); jsonBuffer = new ByteArrayOutputStream(CAPACITY); generator = factory.createJsonGenerator(jsonBuffer); } catch (Exception e) { log.error(e); log.error(e.getStackTrace()); } }
Example 15
Source File: Configuration.java From hadoop with Apache License 2.0 | 5 votes |
/** * Writes out all the parameters and their properties (final and resource) to * the given {@link Writer} * The format of the output would be * { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2, * key2.isFinal,key2.resource}... ] } * It does not output the parameters of the configuration object which is * loaded from an input stream. * @param out the Writer to write to * @throws IOException */ public static void dumpConfiguration(Configuration config, Writer out) throws IOException { JsonFactory dumpFactory = new JsonFactory(); JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out); dumpGenerator.writeStartObject(); dumpGenerator.writeFieldName("properties"); dumpGenerator.writeStartArray(); dumpGenerator.flush(); synchronized (config) { for (Map.Entry<Object,Object> item: config.getProps().entrySet()) { dumpGenerator.writeStartObject(); dumpGenerator.writeStringField("key", (String) item.getKey()); dumpGenerator.writeStringField("value", config.get((String) item.getKey())); dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey())); String[] resources = config.updatingResource.get(item.getKey()); String resource = UNKNOWN_RESOURCE; if(resources != null && resources.length > 0) { resource = resources[0]; } dumpGenerator.writeStringField("resource", resource); dumpGenerator.writeEndObject(); } } dumpGenerator.writeEndArray(); dumpGenerator.writeEndObject(); dumpGenerator.flush(); }
Example 16
Source File: TestHistograms.java From hadoop with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { final Configuration conf = new Configuration(); final FileSystem lfs = FileSystem.getLocal(conf); for (String arg : args) { Path filePath = new Path(arg).makeQualified(lfs); String fileName = filePath.getName(); if (fileName.startsWith("input")) { LoggedDiscreteCDF newResult = histogramFileToCDF(filePath, lfs); String testName = fileName.substring("input".length()); Path goldFilePath = new Path(filePath.getParent(), "gold"+testName); ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getJsonFactory(); FSDataOutputStream ostream = lfs.create(goldFilePath, true); JsonGenerator gen = factory.createJsonGenerator(ostream, JsonEncoding.UTF8); gen.useDefaultPrettyPrinter(); gen.writeObject(newResult); gen.close(); } else { System.err.println("Input file not started with \"input\". File "+fileName+" skipped."); } } }
Example 17
Source File: QueueManager.java From hadoop with Apache License 2.0 | 5 votes |
/*** * Dumps the configuration of hierarchy of queues with * the xml file path given. It is to be used directly ONLY FOR TESTING. * @param out the writer object to which dump is written to. * @param configFile the filename of xml file * @throws IOException */ static void dumpConfiguration(Writer out, String configFile, Configuration conf) throws IOException { if (conf != null && conf.get(DeprecatedQueueConfigurationParser. MAPRED_QUEUE_NAMES_KEY) != null) { return; } JsonFactory dumpFactory = new JsonFactory(); JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out); QueueConfigurationParser parser; boolean aclsEnabled = false; if (conf != null) { aclsEnabled = conf.getBoolean(MRConfig.MR_ACLS_ENABLED, false); } if (configFile != null && !"".equals(configFile)) { parser = new QueueConfigurationParser(configFile, aclsEnabled); } else { parser = getQueueConfigurationParser(null, false, aclsEnabled); } dumpGenerator.writeStartObject(); dumpGenerator.writeFieldName("queues"); dumpGenerator.writeStartArray(); dumpConfiguration(dumpGenerator,parser.getRoot().getChildren()); dumpGenerator.writeEndArray(); dumpGenerator.writeEndObject(); dumpGenerator.flush(); }
Example 18
Source File: Configuration.java From flink with Apache License 2.0 | 5 votes |
/** * Writes out all the parameters and their properties (final and resource) to * the given {@link Writer} * The format of the output would be * { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2, * key2.isFinal,key2.resource}... ] } * It does not output the parameters of the configuration object which is * loaded from an input stream. * @param out the Writer to write to * @throws IOException */ public static void dumpConfiguration(Configuration config, Writer out) throws IOException { JsonFactory dumpFactory = new JsonFactory(); JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out); dumpGenerator.writeStartObject(); dumpGenerator.writeFieldName("properties"); dumpGenerator.writeStartArray(); dumpGenerator.flush(); synchronized (config) { for (Entry<Object,Object> item: config.getProps().entrySet()) { dumpGenerator.writeStartObject(); dumpGenerator.writeStringField("key", (String) item.getKey()); dumpGenerator.writeStringField("value", config.get((String) item.getKey())); dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey())); String[] resources = config.updatingResource.get(item.getKey()); String resource = UNKNOWN_RESOURCE; if(resources != null && resources.length > 0) { resource = resources[0]; } dumpGenerator.writeStringField("resource", resource); dumpGenerator.writeEndObject(); } } dumpGenerator.writeEndArray(); dumpGenerator.writeEndObject(); dumpGenerator.flush(); }
Example 19
Source File: ServiceResponseBuilder.java From WSPerfLab with Apache License 2.0 | 4 votes |
public static ByteArrayOutputStream buildTestAResponse(JsonFactory jsonFactory, BackendResponse responseA, BackendResponse responseB, BackendResponse responseC, BackendResponse responseD, BackendResponse responseE) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(bos); jsonGenerator.writeStartObject(); // multiplication of C, D, E responseKey jsonGenerator.writeNumberField("responseKey", responseC.getResponseKey() + responseD.getResponseKey() + responseE.getResponseKey()); // delay values of each response jsonGenerator.writeArrayFieldStart("delay"); writeTuple(jsonGenerator, "a", responseA.getDelay()); writeTuple(jsonGenerator, "b", responseB.getDelay()); writeTuple(jsonGenerator, "c", responseC.getDelay()); writeTuple(jsonGenerator, "d", responseD.getDelay()); writeTuple(jsonGenerator, "e", responseE.getDelay()); jsonGenerator.writeEndArray(); // itemSize values of each response jsonGenerator.writeArrayFieldStart("itemSize"); writeTuple(jsonGenerator, "a", responseA.getItemSize()); writeTuple(jsonGenerator, "b", responseB.getItemSize()); writeTuple(jsonGenerator, "c", responseC.getItemSize()); writeTuple(jsonGenerator, "d", responseD.getItemSize()); writeTuple(jsonGenerator, "e", responseE.getItemSize()); jsonGenerator.writeEndArray(); // numItems values of each response jsonGenerator.writeArrayFieldStart("numItems"); writeTuple(jsonGenerator, "a", responseA.getNumItems()); writeTuple(jsonGenerator, "b", responseB.getNumItems()); writeTuple(jsonGenerator, "c", responseC.getNumItems()); writeTuple(jsonGenerator, "d", responseD.getNumItems()); writeTuple(jsonGenerator, "e", responseE.getNumItems()); jsonGenerator.writeEndArray(); // all items from responses jsonGenerator.writeArrayFieldStart("items"); addItemsFromResponse(jsonGenerator, responseA); addItemsFromResponse(jsonGenerator, responseB); addItemsFromResponse(jsonGenerator, responseC); addItemsFromResponse(jsonGenerator, responseD); addItemsFromResponse(jsonGenerator, responseE); jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); jsonGenerator.close(); return bos; }
Example 20
Source File: CoTAdapter.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 4 votes |
private void initializeJsonGenerator() throws IOException { factory = new JsonFactory(); jsonBuffer = new ByteArrayOutputStream(CAPACITY); generator = factory.createJsonGenerator(jsonBuffer); }