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

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

本文整理了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

@Override
protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception {
  if (type instanceof ParameterizedType) {
    getJsonb().toJson(o, type, writer);
  }
  else {
    getJsonb().toJson(o, writer);
  }
}

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

@Override
protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception {
  if (type instanceof ParameterizedType) {
    getJsonb().toJson(o, type, writer);
  }
  else {
    getJsonb().toJson(o, writer);
  }
}

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

@Override
public void writeTo(Object o, Class<?> type, Type genericType,
          Annotation[] annotations,
          MediaType mediaType,
          MultivaluedMap<String, Object> httpHeaders,
          OutputStream entityStream) throws IOException, WebApplicationException {
  Jsonb jsonb = getJsonb(type);
  try {
    entityStream.write(jsonb.toJson(o).getBytes(AbstractMessageReaderWriterProvider.getCharset(mediaType)));
    entityStream.flush();
  } catch (IOException e) {
    throw new ProcessingException(LocalizationMessages.ERROR_JSONB_SERIALIZATION(), e);
  }
}

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

@Override
public void render(final Object object, final Context ctx) throws Exception {
 if (ctx.accepts(this.type)) {
  ctx.type(this.type)
    .send(jsonb.toJson(object));
 }
}

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

@Override
public String[] getMessages() {
 try {
   return new String[]{mapper.toJson(messageList)};
 } catch (Exception e) {
   throw new RuntimeException(e);
 }
}

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

@Override
  public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations,
            MediaType mediaType,
            MultivaluedMap<String, Object> httpHeaders,
            OutputStream entityStream)
     throws java.io.IOException, javax.ws.rs.WebApplicationException {
   Jsonb jsonb = getJsonb(type);
   try
   {
     entityStream = new DelegatingOutputStream(entityStream) {
      @Override
      public void flush() throws IOException {
        // don't flush as this is a performance hit on Undertow.
        // and causes chunked encoding to happen.
      }
     };
     entityStream.write(jsonb.toJson(t).getBytes(getCharset(mediaType)));
     entityStream.flush();
   } catch (Throwable e)
   {
     throw new ProcessingException(Messages.MESSAGES.jsonBSerializationError(e.toString()), e);
   }
  }
}

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

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

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

/**
   * Returns a new instance of {@link Value} converting to JSON first
   *
   * @param json the value
   * @return the new Value instance
   * @throws NullPointerException when json is null
   */
  public static Value of(Object json) throws NullPointerException {
    Objects.requireNonNull(json, "json is required");
    return new ValueJSON(JSONB.toJson(json));
  }
}

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

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

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

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

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

@Override
protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception {
  if (type instanceof ParameterizedType) {
    getJsonb().toJson(o, type, writer);
  }
  else {
    getJsonb().toJson(o, writer);
  }
}

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

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

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

@Override
protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception {
  if (type instanceof ParameterizedType) {
    getJsonb().toJson(o, type, writer);
  }
  else {
    getJsonb().toJson(o, writer);
  }
}

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

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

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

public <T> Record toRecord(final T data, final Supplier<Jsonb> jsonbProvider,
    final Supplier<RecordBuilderFactory> recordBuilderProvider) {
  if (Record.class.isInstance(data)) {
    return Record.class.cast(data);
  }
  if (JsonObject.class.isInstance(data)) {
    return json2Record(recordBuilderProvider.get(), JsonObject.class.cast(data));
  }
  final Jsonb jsonb = jsonbProvider.get();
  return json2Record(recordBuilderProvider.get(), jsonb.fromJson(jsonb.toJson(data), JsonObject.class));
}

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

@Override
public <K, V> void put(K key, V value) {
  requireNonNull(key, "key is required");
  requireNonNull(value, "value is required");
  if (JsonValue.checkType(value)) {
    bucket.upsert(RawJsonDocument.create(key.toString(), JSONB.toJson(value.toString())));
  } else {
    bucket.upsert(JsonDocument.create(key.toString(), JsonObjectCouchbaseUtil.toJson(JSONB, value)));
  }
}

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

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

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

@Override
public <K, V> void put(K key, V value) throws NullPointerException {
  Objects.requireNonNull(key, "Key is required");
  Objects.requireNonNull(value, "value is required");
  BaseDocument baseDocument = new BaseDocument();
  baseDocument.setKey(key.toString());
  baseDocument.addAttribute(VALUE, JSONB.toJson(value));
  if (arangoDB.db(bucketName).collection(namespace).documentExists(key.toString())) {
    arangoDB.db(bucketName).collection(namespace).deleteDocument(key.toString());
  }
  arangoDB.db(bucketName).collection(namespace)
      .insertDocument(baseDocument);
}

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

public void save(final CreateProject event) {
  final String project = event.getRequest().getBuildConfiguration().getGroup() + ':'
      + event.getRequest().getBuildConfiguration().getArtifact();
  logger
      .info(jsonb
          .toJson(new Representation(project,
              event.getRequest().getSources() == null ? 0 : event.getRequest().getSources().size(),
              event.getRequest().getProcessors() == null ? 0
                  : event.getRequest().getProcessors().size(),
              ofNullable(event.getRequest().getFacets()).orElseGet(Collections::emptyList))));
}

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

@Benchmark
@Override
public Object yasson() {
  ByteArrayOutputStream baos = JsonUtils.byteArrayOutputStream();
  JSON_SOURCE().provider().yasson().toJson(JSON_SOURCE().nextPojo(), baos);
  return baos;
}

相关文章