当前位置: 首页>>代码示例>>Java>>正文


Java JsonGenerator.write方法代码示例

本文整理汇总了Java中javax.json.stream.JsonGenerator.write方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.write方法的具体用法?Java JsonGenerator.write怎么用?Java JsonGenerator.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.json.stream.JsonGenerator的用法示例。


在下文中一共展示了JsonGenerator.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
/**
    * Build a Json with name and values rom the passed map
    * @param namesAndValues	the map of (name, value) to add to the JsonGenerator
    * @return
    */
   public static String build(Map<String, String> namesAndValues) {

if (namesAndValues == null) {
    throw new NullPointerException("namesAndValues is null");
}

JsonGeneratorFactory jf = JsonUtil.getJsonGeneratorFactory(JsonUtil.DEFAULT_PRETTY_PRINTING);

StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(sw);

gen.writeStartObject()
.write("status", "OK")	;

for (Map.Entry<String, String> entry : namesAndValues.entrySet()) {

    // trace(entry.getKey() + "/" + entry.getValue());
    gen.write(entry.getKey(), entry.getValue());
}

gen.writeEnd();
gen.close();

return sw.toString();
   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:31,代码来源:JsonOkReturn.java

示例2: statementNotAllowedBuild

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
/**
    * Builds a security error message in JSON format for Statements
    * @param sqlOrder
    * @param errorMessage
    * @param doPrettyPrinting
    * @return
    */
   public static String statementNotAllowedBuild(String sqlOrder, String errorMessage, boolean doPrettyPrinting) {

try {
    JsonGeneratorFactory jf = JsonUtil
    	.getJsonGeneratorFactory(doPrettyPrinting);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    
    JsonGenerator gen = jf.createGenerator(out);
    gen.writeStartObject();
    gen.write(Tag.PRODUCT_SECURITY, errorMessage);
    gen.write("SQL order", sqlOrder);
    gen.writeEnd();
    gen.close();
    return out.toString("UTF-8");
} catch (Exception e) {
    String returnString = Tag.PRODUCT_SECURITY + " " + errorMessage
	    + " " + sqlOrder;
    return returnString;
}

   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:30,代码来源:JsonSecurityMessage.java

示例3: testJsonValue

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Test
public void testJsonValue () throws IOException
{
	File file1 = new File ("../tests/data/complex1.json".replace ('/', File.separatorChar));

	// first convert from Json to Bson using stream API
	File bsonFile = testFolder.newFile ();
	CookJsonParser p = TextJsonConfigHandler.getJsonParser (new FileInputStream (file1));
	JsonGenerator g = new BsonGenerator (new FileOutputStream (bsonFile));
	Utils.convert (p, g);
	p.close ();
	g.close ();

	// convert from Json to Bson using tree api
	File bsonFile2 = testFolder.newFile ();
	p = TextJsonConfigHandler.getJsonParser (new FileInputStream (file1));
	p.next ();
	JsonValue value = p.getValue ();
	p.close ();
	g = new BsonGenerator (new FileOutputStream (bsonFile2));
	g.write (value);
	g.close ();

	// due to object ordering, we can only compare the length.
	Assert.assertEquals (bsonFile.length (), bsonFile2.length ());
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:27,代码来源:BsonGeneratorTest.java

示例4: createString

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
public static String createString(Collection<ProjectLicense> projectLicenses)
{
    TreeSet<ProjectLicense> projectLicenseSet = new TreeSet<>();
    projectLicenseSet.addAll(projectLicenses);

    StringWriter jsonString = new StringWriter();
    JsonGenerator generator = Json.createGenerator(jsonString);
    generator.writeStartArray();
    for (ProjectLicense projectLicense : projectLicenseSet)
    {
        generator.writeStartObject();
        generator.write("projectKey", projectLicense.getProjectKey());
        generator.write("license", projectLicense.getLicense());
        generator.write("status", projectLicense.getStatus());
        generator.writeEnd();
    }
    generator.writeEnd();
    generator.close();

    return jsonString.toString();
}
 
开发者ID:porscheinformatik,项目名称:sonarqube-licensecheck,代码行数:22,代码来源:ProjectLicense.java

示例5: createString

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
public static String createString(Collection<MavenLicense> mavenLicenses)
{
    TreeSet<MavenLicense> mavenLicenseSet = new TreeSet<>();
    mavenLicenseSet.addAll(mavenLicenses);

    StringWriter jsonString = new StringWriter();
    JsonGenerator generator = Json.createGenerator(jsonString);
    generator.writeStartArray();
    for (MavenLicense mavenLicense : mavenLicenseSet)
    {
        generator.writeStartObject();
        generator.write("regex", mavenLicense.getRegex().pattern());
        generator.write("license", mavenLicense.getLicense());
        generator.writeEnd();
    }
    generator.writeEnd();
    generator.close();

    return jsonString.toString();
}
 
开发者ID:porscheinformatik,项目名称:sonarqube-licensecheck,代码行数:21,代码来源:MavenLicense.java

示例6: serialize

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Book book, JsonGenerator generator, SerializationContext ctx) {
    generator.writeStartObject();
    generator.write("id", "QWE-123-RTS");
    generator.write("title", book.getTitle());
    generator.write("firstName", book.getAuthor().split(" ")[0]);
    generator.write("lastName", book.getAuthor().split(" ")[1]);
    generator.writeEnd();
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:10,代码来源:BookSerializer.java

示例7: build

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
/**
    * Builds the error message
    * @return the error message
    */
   public String build() {

JsonGeneratorFactory jf = JsonUtil.getJsonGeneratorFactory(JsonUtil.DEFAULT_PRETTY_PRINTING);
    
StringWriter sw = new StringWriter();	
JsonGenerator gen = jf.createGenerator(sw);

gen.writeStartObject()
   .write("status", "FAIL")
   .write("error_type", errorType);

if (errorMessage != null) {
    gen.write("error_message", errorMessage);
}
else {
    gen.write("error_message", JsonValue.NULL);
}

if (stackTrace != null) {
    gen.write("stack_trace", stackTrace);
    System.err.println(stackTrace);
}

gen.write("http_status", httpStatus);

gen.writeEnd();
gen.close();

String doc = sw.toString();

if (LOG_JSON_ERROR) {
    System.err.println(doc);
}

return doc;
   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:41,代码来源:JsonErrorReturn.java

示例8: serialize

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(final CoffeeEvent event, final JsonGenerator generator, final SerializationContext ctx) {
    generator.write("class", event.getClass().getCanonicalName());
    generator.writeStartObject("data");
    ctx.serialize("data", event, generator);
    generator.writeEnd();
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:8,代码来源:EventJsonbSerializer.java

示例9: testJsonValuePrettyJson

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Test
public void testJsonValuePrettyJson () throws IOException
{
	File file1 = new File ("../tests/data/binary.bson".replace ('/', File.separatorChar));
	File file2 = new File ("../tests/data/binary.json".replace ('/', File.separatorChar));

	CookJsonProvider provider = new CookJsonProvider ();
	HashMap<String, Object> bsonConfig = new HashMap<String, Object> ();
	bsonConfig.put (CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_BSON);
	bsonConfig.put (CookJsonProvider.ROOT_AS_ARRAY, Boolean.TRUE);

	HashMap<String, Object> jsonConfig = new HashMap<String, Object> ();
	jsonConfig.put (JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);

	File jsonFile1 = testFolder.newFile ();
	CookJsonParser p = (CookJsonParser) provider.createParserFactory (bsonConfig).createParser (new FileInputStream (file1));
	p.next ();
	JsonValue value = p.getValue ();
	JsonGenerator g = provider.createGeneratorFactory (jsonConfig).createGenerator (new FileOutputStream (jsonFile1));
	g.write (value);
	p.close ();
	g.close ();

	File jsonFile2 = testFolder.newFile ();
	JsonParser p2 = provider.createParserFactory (jsonConfig).createParser (new FileInputStream (file2));
	JsonGenerator g2 = provider.createGeneratorFactory (jsonConfig).createGenerator (new FileOutputStream (jsonFile2));
	Utils.convert (p2, g2);
	p2.close ();
	g2.close ();

	FileAssert.assertBinaryEquals (jsonFile2, jsonFile1);
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:33,代码来源:BinaryTest.java

示例10: serialize

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void serialize(Number obj, JsonGenerator generator, Marshaller marshaller) {
    BigDecimal bigDecimalValue = new BigDecimal(String.valueOf(obj));
    if (BigNumberUtil.isIEEE754(bigDecimalValue)) {
        generator.write(bigDecimalValue);
    } else {
        generator.write(String.valueOf(obj));
    }
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:10,代码来源:NumberTypeSerializer.java

示例11: toJson

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
public void toJson(JsonGenerator generator) {
    generator.write("workflowId", workflowId);
    generator.writeStartObject("ruleDescription");
    //TODO
    generator.writeEnd();
}
 
开发者ID:itesla,项目名称:ipst,代码行数:8,代码来源:SecurityRuleDescriptionMessage.java

示例12: writeDate

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
private void writeDate(JsonGenerator jg, String key, Date date) {
    if (date != null) {
        String formattedDate = getFormattedDate(date);
        jg.write(key, formattedDate);
    } else {
        jg.write(key, JsonValue.NULL);
    }
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:9,代码来源:QueryResultMessageBodyWriter.java

示例13: serialize

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Crate obj, JsonGenerator generator, SerializationContext ctx) {
    generator.writeStartObject();
    generator.write("crateStr", "REPLACED crate str");
    ctx.serialize("crateInner", obj.crateInner, generator);
    ctx.serialize("crateInnerList", obj.crateInnerList, generator);
    generator.write("crateBigDec", new BigDecimal("54321"));
    generator.writeEnd();
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:10,代码来源:CrateSerializer.java

示例14: testJsonValueBson

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
private void testJsonValueBson (String f) throws IOException
{
	File file = new File (f.replace ('/', File.separatorChar));

	JsonValue value;

	BsonParser p = new BsonParser (new FileInputStream (file));
	p.setRootAsArray (true);
	p.next ();
	value = p.getValue ();
	p.close ();

	StringWriter out1 = new StringWriter ();
	JsonGenerator g1 = new TextJsonGenerator (out1);
	g1.writeStartArray ();
	g1.write (value);
	g1.writeEnd ();
	g1.close ();

	JsonProvider provider = new org.glassfish.json.JsonProviderImpl ();
	StringWriter out2 = new StringWriter ();
	JsonGenerator g2 = provider.createGenerator (out2);
	g2.writeStartArray ();
	g2.write (value);
	g2.writeEnd ();
	g2.close ();

	Assert.assertEquals (out1.toString (), out2.toString ());
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:30,代码来源:TextJsonGeneratorTest.java

示例15: serializeInternal

import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void serializeInternal(byte[] obj, JsonGenerator generator, SerializationContext ctx) {
    for (byte b : obj) {
        generator.write(b);
    }
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:7,代码来源:ByteArraySerializer.java


注:本文中的javax.json.stream.JsonGenerator.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。