javax.json.bind.Jsonb.toJson()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中javax.json.bind.Jsonb.toJson()方法的一些代码示例,展示了Jsonb.toJson()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jsonb.toJson()方法的具体详情如下:
包路径:javax.json.bind.Jsonb
类名称:Jsonb
方法名:toJson

Jsonb.toJson介绍

[英]Writes the Java object tree with root object object to a String instance as JSON.
[中]将带有根对象的Java对象树作为JSON写入字符串实例。

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception {
  3. if (type instanceof ParameterizedType) {
  4. getJsonb().toJson(o, type, writer);
  5. }
  6. else {
  7. getJsonb().toJson(o, writer);
  8. }
  9. }

代码示例来源:origin: org.springframework/spring-web

  1. @Override
  2. protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception {
  3. if (type instanceof ParameterizedType) {
  4. getJsonb().toJson(o, type, writer);
  5. }
  6. else {
  7. getJsonb().toJson(o, writer);
  8. }
  9. }

代码示例来源:origin: jersey/jersey

  1. @Override
  2. public void writeTo(Object o, Class<?> type, Type genericType,
  3. Annotation[] annotations,
  4. MediaType mediaType,
  5. MultivaluedMap<String, Object> httpHeaders,
  6. OutputStream entityStream) throws IOException, WebApplicationException {
  7. Jsonb jsonb = getJsonb(type);
  8. try {
  9. entityStream.write(jsonb.toJson(o).getBytes(AbstractMessageReaderWriterProvider.getCharset(mediaType)));
  10. entityStream.flush();
  11. } catch (IOException e) {
  12. throw new ProcessingException(LocalizationMessages.ERROR_JSONB_SERIALIZATION(), e);
  13. }
  14. }

代码示例来源:origin: jooby-project/jooby

  1. @Override
  2. public void render(final Object object, final Context ctx) throws Exception {
  3. if (ctx.accepts(this.type)) {
  4. ctx.type(this.type)
  5. .send(jsonb.toJson(object));
  6. }
  7. }

代码示例来源:origin: resteasy/Resteasy

  1. @Override
  2. public String[] getMessages() {
  3. try {
  4. return new String[]{mapper.toJson(messageList)};
  5. } catch (Exception e) {
  6. throw new RuntimeException(e);
  7. }
  8. }

代码示例来源:origin: resteasy/Resteasy

  1. @Override
  2. public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations,
  3. MediaType mediaType,
  4. MultivaluedMap<String, Object> httpHeaders,
  5. OutputStream entityStream)
  6. throws java.io.IOException, javax.ws.rs.WebApplicationException {
  7. Jsonb jsonb = getJsonb(type);
  8. try
  9. {
  10. entityStream = new DelegatingOutputStream(entityStream) {
  11. @Override
  12. public void flush() throws IOException {
  13. // don't flush as this is a performance hit on Undertow.
  14. // and causes chunked encoding to happen.
  15. }
  16. };
  17. entityStream.write(jsonb.toJson(t).getBytes(getCharset(mediaType)));
  18. entityStream.flush();
  19. } catch (Throwable e)
  20. {
  21. throw new ProcessingException(Messages.MESSAGES.jsonBSerializationError(e.toString()), e);
  22. }
  23. }
  24. }

代码示例来源:origin: org.apache.geronimo/geronimo-opentracing-common

  1. @Override
  2. public void onEvent(final ZipkinSpan zipkinSpan) {
  3. final String json = jsonb.toJson(zipkinSpan);
  4. spanLogger.info(wrapAsList ? '[' + json + ']' : json);
  5. }
  6. }

代码示例来源:origin: org.jnosql.diana/diana-driver-commons

  1. /**
  2. * Returns a new instance of {@link Value} converting to JSON first
  3. *
  4. * @param json the value
  5. * @return the new Value instance
  6. * @throws NullPointerException when json is null
  7. */
  8. public static Value of(Object json) throws NullPointerException {
  9. Objects.requireNonNull(json, "json is required");
  10. return new ValueJSON(JSONB.toJson(json));
  11. }
  12. }

代码示例来源:origin: org.jnosql.diana/couchbase-driver

  1. @Override
  2. public boolean add(T t) {
  3. requireNonNull(t, "object is required");
  4. return arraySet.add(JSONB.toJson(t));
  5. }

代码示例来源:origin: apache/johnzon

  1. @Override
  2. public void writeTo(final T t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType,
  3. final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException {
  4. getJsonb(type).toJson(t, entityStream);
  5. }

代码示例来源:origin: apache/servicemix-bundles

  1. @Override
  2. protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception {
  3. if (type instanceof ParameterizedType) {
  4. getJsonb().toJson(o, type, writer);
  5. }
  6. else {
  7. getJsonb().toJson(o, writer);
  8. }
  9. }

代码示例来源:origin: org.apache.johnzon/johnzon-jsonb

  1. @Override
  2. public void writeTo(final T t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType,
  3. final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException {
  4. getJsonb(type).toJson(t, entityStream);
  5. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

  1. @Override
  2. protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception {
  3. if (type instanceof ParameterizedType) {
  4. getJsonb().toJson(o, type, writer);
  5. }
  6. else {
  7. getJsonb().toJson(o, writer);
  8. }
  9. }

代码示例来源:origin: org.jnosql.diana/couchbase-driver

  1. @Override
  2. public boolean retainAll(Collection<?> collection) {
  3. requireNonNull(collection, "collection is required");
  4. collection.removeIf(e -> !arraySet.contains(JSONB.toJson(e)));
  5. return true;
  6. }

代码示例来源:origin: org.talend.sdk.component/component-runtime-impl

  1. public <T> Record toRecord(final T data, final Supplier<Jsonb> jsonbProvider,
  2. final Supplier<RecordBuilderFactory> recordBuilderProvider) {
  3. if (Record.class.isInstance(data)) {
  4. return Record.class.cast(data);
  5. }
  6. if (JsonObject.class.isInstance(data)) {
  7. return json2Record(recordBuilderProvider.get(), JsonObject.class.cast(data));
  8. }
  9. final Jsonb jsonb = jsonbProvider.get();
  10. return json2Record(recordBuilderProvider.get(), jsonb.fromJson(jsonb.toJson(data), JsonObject.class));
  11. }

代码示例来源:origin: org.jnosql.diana/couchbase-driver

  1. @Override
  2. public <K, V> void put(K key, V value) {
  3. requireNonNull(key, "key is required");
  4. requireNonNull(value, "value is required");
  5. if (JsonValue.checkType(value)) {
  6. bucket.upsert(RawJsonDocument.create(key.toString(), JSONB.toJson(value.toString())));
  7. } else {
  8. bucket.upsert(JsonDocument.create(key.toString(), JsonObjectCouchbaseUtil.toJson(JSONB, value)));
  9. }
  10. }

代码示例来源:origin: org.talend.sdk.component/component-server

  1. private String toDefault(final DefaultValueInspector.Instance instance, final ParameterMeta p) {
  2. if (instance.isCreated()) {
  3. return null;
  4. }
  5. if (Collection.class.isInstance(instance.getValue()) || Map.class.isInstance(instance.getValue())) {
  6. // @Experimental("not primitives are a challenge, for now use that but can change if not adapted")
  7. return defaultMapper.toJson(instance.getValue());
  8. }
  9. return defaultValueInspector.findDefault(instance.getValue(), p);
  10. }

代码示例来源:origin: org.jnosql.diana/arangodb-driver

  1. @Override
  2. public <K, V> void put(K key, V value) throws NullPointerException {
  3. Objects.requireNonNull(key, "Key is required");
  4. Objects.requireNonNull(value, "value is required");
  5. BaseDocument baseDocument = new BaseDocument();
  6. baseDocument.setKey(key.toString());
  7. baseDocument.addAttribute(VALUE, JSONB.toJson(value));
  8. if (arangoDB.db(bucketName).collection(namespace).documentExists(key.toString())) {
  9. arangoDB.db(bucketName).collection(namespace).deleteDocument(key.toString());
  10. }
  11. arangoDB.db(bucketName).collection(namespace)
  12. .insertDocument(baseDocument);
  13. }

代码示例来源:origin: org.talend.sdk.component/component-starter-server

  1. public void save(final CreateProject event) {
  2. final String project = event.getRequest().getBuildConfiguration().getGroup() + ':'
  3. + event.getRequest().getBuildConfiguration().getArtifact();
  4. logger
  5. .info(jsonb
  6. .toJson(new Representation(project,
  7. event.getRequest().getSources() == null ? 0 : event.getRequest().getSources().size(),
  8. event.getRequest().getProcessors() == null ? 0
  9. : event.getRequest().getProcessors().size(),
  10. ofNullable(event.getRequest().getFacets()).orElseGet(Collections::emptyList))));
  11. }

代码示例来源:origin: fabienrenaud/java-json-benchmark

  1. @Benchmark
  2. @Override
  3. public Object yasson() {
  4. ByteArrayOutputStream baos = JsonUtils.byteArrayOutputStream();
  5. JSON_SOURCE().provider().yasson().toJson(JSON_SOURCE().nextPojo(), baos);
  6. return baos;
  7. }

相关文章