本文整理汇总了Java中org.codehaus.jackson.JsonFactory.createJsonGenerator方法的典型用法代码示例。如果您正苦于以下问题:Java JsonFactory.createJsonGenerator方法的具体用法?Java JsonFactory.createJsonGenerator怎么用?Java JsonFactory.createJsonGenerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.JsonFactory
的用法示例。
在下文中一共展示了JsonFactory.createJsonGenerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
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();
}
示例2: main
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
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.");
}
}
}
示例3: dumpConfiguration
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
/**
* 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();
}
示例4: writeToResponse
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
/**
* Writes the response values back to the http response. This allows the calling code to
* parse the response values for display to the user.
*
* @param responseMap the response params to write to the http response
* @param response the http response
* @throws IOException
*/
private static void writeToResponse(Map<String, String> responseMap, HttpServletResponse response) throws IOException {
// Note: setting the content-type to text/html because otherwise IE prompt the user to download
// the result rather than handing it off to the GWT form response handler.
// See JIRA issue https://issues.jboss.org/browse/SRAMPUI-103
response.setContentType("text/html; charset=UTF8"); //$NON-NLS-1$
JsonFactory f = new JsonFactory();
JsonGenerator g = f.createJsonGenerator(response.getOutputStream(), JsonEncoding.UTF8);
g.useDefaultPrettyPrinter();
g.writeStartObject();
for (java.util.Map.Entry<String, String> entry : responseMap.entrySet()) {
String key = entry.getKey();
String val = entry.getValue();
g.writeStringField(key, val);
}
g.writeEndObject();
g.flush();
g.close();
}
示例5: open
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
/**
* Open a JSON output file
* The file output may be derived from many input sources
*
* @param name
* @param string
* @throws XMLStreamException
* @throws IOException
*/
public void open(File file) throws XMLStreamException, IOException {
// Mapped convention
JsonFactory f = new JsonFactory();
try {
generator = f.createJsonGenerator(new FileWriter(file));
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
generator.setCodec(mapper);
generator.useDefaultPrettyPrinter();
rootNode = mapper.createObjectNode();
rootNode.put("name", "odfestyles");
rootArray = rootNode.putArray(CHILDREN_TAG);
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例6: open
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
public void open(File file) throws XMLStreamException, IOException {
// Mapped convention
JsonFactory f = new JsonFactory();
try {
generator = f.createJsonGenerator(new FileWriter(file));
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
generator.setCodec(mapper);
generator.useDefaultPrettyPrinter();
rootNode = mapper.createObjectNode();
rootNode.put("name", "odfpaths");
rootArray = rootNode.putArray(CHILDREN_TAG);
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例7: test1
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
@Test
public void test1() throws JsonGenerationException, IOException {
JsonFactory f = new JsonFactory();
JsonGenerator g = f.createJsonGenerator(new File(
"src/main/resources/user6.json"), JsonEncoding.UTF8);
g.writeStartObject();
g.writeObjectFieldStart("name");
g.writeStringField("first", "Joe");
g.writeStringField("last", "Sixpack");
g.writeEndObject(); // for field 'name'
g.writeStringField("gender", Gender.MALE.toString());
g.writeBooleanField("verified", false);
g.writeFieldName("userImage"); // no 'writeBinaryField' (yet?)
byte[] binaryData = new byte[3];
g.writeBinary(binaryData);
g.writeEndObject();
g.close(); // important: will force flushing of output, close underlying
// output stream
}
示例8: getRandomLogJson
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
public static String getRandomLogJson() {
JsonFactory jsonfactory = new JsonFactory();
Writer writer = new StringWriter();
String json = null;
try {
JsonGenerator jsonGenerator = jsonfactory.createJsonGenerator(writer);
jsonGenerator.writeStartObject();
jsonGenerator.writeArrayFieldStart("logs");
jsonGenerator.writeString("authenticationToken must be at least 16 characters.");
jsonGenerator.writeString("Downloading push notification package failed.");
jsonGenerator.writeString("Extracting push notification package failed.");
jsonGenerator.writeString("Missing file in push notification package.");
jsonGenerator.writeString("Missing image in push notification package.");
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
jsonGenerator.close();
json = writer.toString();
} catch (IOException e) {
e.printStackTrace();
}
return json;
}
示例9: dumpConfiguration
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
/**
* 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 conf,
Writer out) throws IOException {
Configuration config = new Configuration(conf,true);
config.reloadConfiguration();
JsonFactory dumpFactory = new JsonFactory();
JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
dumpGenerator.writeStartObject();
dumpGenerator.writeFieldName("properties");
dumpGenerator.writeStartArray();
dumpGenerator.flush();
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();
}
示例10: groupToStrings
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
@Override
protected List<String> groupToStrings(SimpleGroup grp) {
JsonGenerator generator;
CharArrayWriter jWriter;
List<String> jls = new ArrayList<>();
jWriter = new CharArrayWriter();
JsonFactory jFactory = new JsonFactory();
try {
generator = jFactory.createJsonGenerator(jWriter);
groupToJson(generator,grp);
generator.close();
}
catch (Exception e) {
e.printStackTrace();
return null;
}
jls.add(jWriter.toString());
return jls;
}
示例11: getPlayerStatus
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
private void getPlayerStatus() throws IOException { // WIP - may need it for startup condition?
JsonFactory factory = new JsonFactory();
JsonGenerator jsonGenerator = factory.createJsonGenerator(myOutputStream);
jsonGenerator.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); //stop jasonGenerator.close from closing stream
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("jsonrpc", "2.0");
jsonGenerator.writeStringField("method", "Player.GetProperties");
jsonGenerator.writeStringField("id", "PlayerGetProperties");
jsonGenerator.writeArrayFieldStart("params");
jsonGenerator.writeStringField("playerid", "1");
jsonGenerator.writeArrayFieldStart("properties");
jsonGenerator.writeString("speed");
jsonGenerator.writeEndArray();
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
jsonGenerator.close();
}
示例12: doSchema
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
private void doSchema(
final FSDataOutputStream fsDataOutputStream,
final String namespace,
final FeatureClass featureClass,
final IGPMessages messages) throws IOException
{
final int wkid = getWkid(featureClass);
final JsonFactory jsonFactory = new JsonFactory();
final JsonGenerator g = jsonFactory.createJsonGenerator(fsDataOutputStream);
try
{
g.writeStartObject();
g.writeStringField("type", "record");
g.writeStringField("namespace", namespace);
g.writeStringField("name", featureClass.getName());
g.writeArrayFieldStart("fields");
writeShape(g, namespace, featureClass.getShapeType(), wkid, messages);
writeFields(g, featureClass, messages);
g.writeEndArray();
g.writeEndObject();
}
finally
{
g.close();
}
}
示例13: writeToResponse
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
/**
* Writes the response values back to the http response. This allows the calling code to
* parse the response values for display to the user.
*
* @param responseMap the response params to write to the http response
* @param response the http response
* @throws IOException
*/
private void writeToResponse(Map<String, String> responseMap, HttpServletResponse response) throws IOException {
// Note: setting the content-type to text/html because otherwise IE prompt the user to download
// the result rather than handing it off to the GWT form response handler.
// See JIRA issue https://issues.jboss.org/browse/SRAMPUI-103
response.setContentType("text/html; charset=UTF8"); //$NON-NLS-1$
JsonFactory f = new JsonFactory();
JsonGenerator g = f.createJsonGenerator(response.getOutputStream(), JsonEncoding.UTF8);
g.useDefaultPrettyPrinter();
g.writeStartObject();
for (java.util.Map.Entry<String, String> entry : responseMap.entrySet()) {
String key = entry.getKey();
String val = entry.getValue();
g.writeStringField(key, val);
}
g.writeEndObject();
g.flush();
g.close();
}
示例14: topologyWriterInit
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
private static boolean topologyWriterInit() {
try {
JsonFactory jfactory = new JsonFactory();
JsonGenerator jGenerator = jfactory.createJsonGenerator(new File(
exportFileName), JsonEncoding.UTF8);
jGenerator.useDefaultPrettyPrinter();
SingletonRegistry.addInstance(JsonGenerator.class.getName(), jGenerator);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
示例15: writeValues
import org.codehaus.jackson.JsonFactory; //导入方法依赖的package包/类
@Override
public void writeValues(Iterator<T> values, OutputStream out) throws IOException{
long st = System.currentTimeMillis();
JsonFactory jsonFactory = mapper.getJsonFactory();
JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(out);
jsonGenerator.writeStartArray();
while (values.hasNext()) {
T next = values.next();
jsonGenerator.writeObject(next);
}
jsonGenerator.writeEndArray();
jsonGenerator.close();
if (ExternalMergeSort.debug) {
System.out.println("W: " + (System.currentTimeMillis() - st) + "ms");
}
}