本文整理了Java中javax.json.Json.createGenerator()
方法的一些代码示例,展示了Json.createGenerator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.createGenerator()
方法的具体详情如下:
包路径:javax.json.Json
类名称:Json
方法名:createGenerator
[英]Creates a JSON generator for writing JSON to a byte stream.
[中]创建用于将JSON写入字节流的JSON生成器。
代码示例来源:origin: org.locationtech.geogig/geogig-web-api
JSONStreamingWriter(Writer writer) {
json = Json.createGenerator(writer);
}
代码示例来源:origin: org.apache.sling/org.apache.sling.junit.core
public void setup(HttpServletResponse response, String pageTitle) throws IOException, UnsupportedEncodingException {
if(writer != null) {
throw new IllegalStateException("Output Writer already set");
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
writer = Json.createGenerator(response.getWriter());
try {
writer.writeStartArray();
} catch(JsonException jex) {
throw (IOException)new IOException().initCause(jex);
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.pipes
public static String toString(JsonValue value) {
StringWriter writer = new StringWriter();
Json.createGenerator(writer).write(value).close();
return writer.toString();
}
代码示例来源:origin: org.apache.sling/org.apache.sling.discovery.base
private static String asJSON(JsonValue json) {
StringWriter writer = new StringWriter();
Json.createGenerator(writer).write(json).close();
return writer.toString();
}
代码示例来源:origin: org.apache.sling/org.apache.sling.servlets.post
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Override
protected void doSend(HttpServletResponse response) throws IOException {
response.setContentType(RESPONSE_CONTENT_TYPE);
response.setCharacterEncoding(RESPONSE_CHARSET);
Json.createGenerator(response.getWriter()).write(getJson()).close();
}
代码示例来源:origin: org.apache.sling/org.apache.sling.pipes
@Override
public void starts() {
jsonWriter = Json.createGenerator(writer);
jsonWriter.writeStartObject();
jsonWriter.writeStartArray(KEY_ITEMS);
}
代码示例来源:origin: org.glassfish/javax.faces
/**
* Encodes the given object as JSON while streaming the string in JSON format to the given writer.
* The encoded object will be available as <code>data</code> property of the JS object in the returned JSON string.
*
* @param object The object to be encoded as JSON.
* @param writer The writer to stream the encoded output to.
* @param options The encoding options.
* @throws IllegalArgumentException When given object or one of its properties cannot be inspected as a JavaBean.
*/
public static void encode(Object object, Writer writer, Option... options) {
try (JsonGenerator generator = javax.json.Json.createGenerator(writer)) {
generator.writeStartObject();
encode("data", object, generator, options.length == 0 ? noneOf(Option.class) : copyOf(asList(options)));
generator.writeEnd();
}
}
代码示例来源:origin: org.glassfish/jakarta.faces
/**
* Encodes the given object as JSON while streaming the string in JSON format to the given writer.
* The encoded object will be available as <code>data</code> property of the JS object in the returned JSON string.
*
* @param object The object to be encoded as JSON.
* @param writer The writer to stream the encoded output to.
* @param options The encoding options.
* @throws IllegalArgumentException When given object or one of its properties cannot be inspected as a JavaBean.
*/
public static void encode(Object object, Writer writer, Option... options) {
try (JsonGenerator generator = javax.json.Json.createGenerator(writer)) {
generator.writeStartObject();
encode("data", object, generator, options.length == 0 ? noneOf(Option.class) : copyOf(asList(options)));
generator.writeEnd();
}
}
代码示例来源:origin: eclipse-ee4j/mojarra
/**
* Encodes the given object as JSON while streaming the string in JSON format to the given writer.
* The encoded object will be available as <code>data</code> property of the JS object in the returned JSON string.
*
* @param object The object to be encoded as JSON.
* @param writer The writer to stream the encoded output to.
* @param options The encoding options.
* @throws IllegalArgumentException When given object or one of its properties cannot be inspected as a JavaBean.
*/
public static void encode(Object object, Writer writer, Option... options) {
try (JsonGenerator generator = javax.json.Json.createGenerator(writer)) {
generator.writeStartObject();
encode("data", object, generator, options.length == 0 ? noneOf(Option.class) : copyOf(asList(options)));
generator.writeEnd();
}
}
代码示例来源:origin: org.dcm4che.tool/dcm4che-tool-qc
private static JsonObject toAttributesObject(Attributes targetSeriesAttrs) {
StringWriter strWriter = new StringWriter();
JsonGenerator gen = Json.createGenerator(strWriter);
JSONWriter writer = new JSONWriter(gen);
writer.write(targetSeriesAttrs);
gen.flush();
gen.close();
return Json.createReader(new StringReader(strWriter.toString()))
.readObject();
}
代码示例来源:origin: eu.agilejava/snoop-client
public String toJSON() {
Writer w = new StringWriter();
try (JsonGenerator generator = Json.createGenerator(w)) {
generator.writeStartObject()
.write("serviceName", serviceName)
.write("serviceHome", serviceHome)
.write("serviceRoot", serviceRoot)
.writeEnd();
}
return w.toString();
}
代码示例来源:origin: ivargrimstad/snoop
public String toJSON() {
Writer w = new StringWriter();
try (JsonGenerator generator = Json.createGenerator(w)) {
generator.writeStartObject()
.write("serviceName", serviceName)
.write("serviceHome", serviceHome)
.write("serviceRoot", serviceRoot)
.writeEnd();
}
return w.toString();
}
代码示例来源:origin: org.apache.sling/org.apache.sling.servlets.get
private void renderJson(final SlingHttpServletResponse response, final Map<String, String> data)
throws IOException {
// render data in JSON format
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
final Writer out = response.getWriter();
//deliberately not closing, as that closes the response out.
final JsonGenerator w = Json.createGenerator(out);
w.writeStartObject();
for (final Map.Entry<String, String> e : data.entrySet()) {
w.write(e.getKey(), e.getValue());
}
w.writeEnd();
w.flush();
}
代码示例来源:origin: org.diirt/web-pods-common
/**
* Utility to serialize just the message and id. More then one message
* only serialize those two parameters, so it is useful to make it common.
*
* @param writer the destination where to serialize the message
*/
void basicToJson(Writer writer) {
JsonGenerator gen = Json.createGenerator(writer).writeStartObject();
gen.write("message", getMessage().toString().toLowerCase())
.write("id", getId())
.writeEnd()
.close();
}
代码示例来源:origin: org.diirt/web-pods-common
@Override
public void toJson(Writer writer) {
JsonGenerator gen = Json.createGenerator(writer).writeStartObject();
gen.write("message", getMessage().toString().toLowerCase())
.write("id", getId());
writeValueToJson(gen, "value", value);
gen.writeEnd()
.close();
}
}
代码示例来源:origin: org.diirt/web-pods-common
@Override
public void toJson(Writer writer) {
JsonGenerator gen = Json.createGenerator(writer).writeStartObject()
.write("message", getMessage().toString().toLowerCase())
.write("id", getId())
.write("type", "value");
writeValueToJson(gen, "value", value);
gen.writeEnd().close();
}
代码示例来源:origin: org.diirt/web-pods-common
@Override
public void toJson(Writer writer) {
Json.createGenerator(writer).writeStartObject()
.write("message", getMessage().toString().toLowerCase())
.write("id", getId())
.write("type", "error")
.write("error", getError())
.writeEnd()
.close();
}
代码示例来源:origin: org.diirt/web-pods-common
@Override
public void toJson(Writer writer) {
Json.createGenerator(writer).writeStartObject()
.write("message", getMessage().toString().toLowerCase())
.write("id", getId())
.write("type", "connection")
.write("connected", isConnected())
.write("writeConnected", isWriteConnected())
.writeEnd()
.close();
}
代码示例来源:origin: org.diirt/web-pods-common
@Override
public void toJson(Writer writer) {
JsonGenerator gen = Json.createGenerator(writer).writeStartObject()
.write("message", getMessage().toString().toLowerCase())
.write("id", getId())
.write("type", "writeCompleted")
.write("successful", isSuccessful());
if (getError() != null) {
gen.write("error", getError());
}
gen.writeEnd().close();
}
代码示例来源:origin: agoncal/agoncal-book-javaee7
public StringWriter generateCreditCard() throws IOException {
CreditCard05 creditCard = new CreditCard05("1234", "12/09", 6398, "Visa");
StringWriter writer = new StringWriter();
JsonGenerator generator = Json.createGenerator(writer);
generator.writeStartObject()
.writeStartObject("creditCard")
.write("number", creditCard.getNumber())
.write("expiryDate", creditCard.getExpiryDate())
.write("controlNumber", creditCard.getControlNumber())
.write("type", creditCard.getType())
.writeEnd()
.writeEnd()
.close();
return writer;
}
内容来源于网络,如有侵权,请联系作者删除!