本文整理汇总了Java中javax.json.Json.createWriter方法的典型用法代码示例。如果您正苦于以下问题:Java Json.createWriter方法的具体用法?Java Json.createWriter怎么用?Java Json.createWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.Json
的用法示例。
在下文中一共展示了Json.createWriter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unwrapJsonObjects
import javax.json.Json; //导入方法依赖的package包/类
public static Object unwrapJsonObjects(Object entity) {
if (entity instanceof JsonObjectBuilder) {
JsonObjectBuilder jsonObjectBuilder = (JsonObjectBuilder) entity;
entity = jsonObjectBuilder.build();
}
if (entity instanceof JsonStructure) {
StringWriter buffer = new StringWriter();
JsonWriter writer = Json.createWriter(buffer);
writer.write((JsonStructure) entity);
writer.close();
return buffer.toString();
}
return entity;
}
示例2: writeJsonStructure
import javax.json.Json; //导入方法依赖的package包/类
public String writeJsonStructure() {
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = Json.createWriter(stringWriter);
jsonWriter.writeObject(new ObjectExample3().buildJsonDocument());
jsonWriter.close();
return stringWriter.toString();
}
示例3: toJson
import javax.json.Json; //导入方法依赖的package包/类
@Override
public void toJson(OutputStream os, Reservation reservation) {
Objects.requireNonNull(reservation, RESERVATION_ISNT_ALLOWED_TO_BE_NULL);
JsonWriter jsonWriter = Json.createWriter(os);
jsonWriter.writeObject(toJson(reservation));
jsonWriter.close();
}
示例4: writeTo
import javax.json.Json; //导入方法依赖的package包/类
@Override
public void writeTo(Set<Reservation> set, Class<?> clazz, Type type, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os)
throws IOException, WebApplicationException {
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
Iterator<Reservation> reservations = set.iterator();
while (reservations.hasNext()) {
Reservation reservation = reservations.next();
arrayBuilder.add(reservationJsonAdapter.toJson(reservation));
}
JsonWriter jsonWriter = Json.createWriter(os);
jsonWriter.writeArray(arrayBuilder.build());
jsonWriter.close();
}
示例5: main
import javax.json.Json; //导入方法依赖的package包/类
public static void main(String ...arg) throws IOException {
File file = new File("json-output.json");
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
if (!file.exists()) {
file.createNewFile();
}
JsonWriter jsonWriter = Json.createWriter(fileOutputStream);
jsonWriter.writeObject(new ObjectExample3().buildJsonDocument());
jsonWriter.close();
// Flush and close file output streams
fileOutputStream.flush();
fileOutputStream.close();
}
}
示例6: writeTo
import javax.json.Json; //导入方法依赖的package包/类
public static void writeTo(DecisionDao t,OutputStream out) throws IOException {
try (JsonWriter writer = Json.createWriter(out)) {
writer.write(getJson(t));
}
}