本文整理了Java中javax.json.bind.Jsonb.fromJson()
方法的一些代码示例,展示了Jsonb.fromJson()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jsonb.fromJson()
方法的具体详情如下:
包路径:javax.json.bind.Jsonb
类名称:Jsonb
方法名:fromJson
[英]Reads in a JSON data from the specified InputStream and return the resulting content tree.
[中]从指定的InputStream读入JSON数据并返回结果内容树。
代码示例来源:origin: spring-projects/spring-framework
@Override
protected Object readInternal(Type resolvedType, Reader reader) throws Exception {
return getJsonb().fromJson(reader, resolvedType);
}
代码示例来源:origin: org.springframework/spring-web
@Override
protected Object readInternal(Type resolvedType, Reader reader) throws Exception {
return getJsonb().fromJson(reader, resolvedType);
}
代码示例来源:origin: jersey/jersey
@Override
public Object readFrom(Class<Object> type, Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException, WebApplicationException {
Jsonb jsonb = getJsonb(type);
try {
return jsonb.fromJson(entityStream, genericType);
} catch (JsonbException e) {
throw new ProcessingException(LocalizationMessages.ERROR_JSONB_DESERIALIZATION(), e);
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable {
MediaType ctype = ctx.type();
if (ctype.isAny()) {
// */*
return ctx.next();
}
if (ctype.matches(this.type)) {
return ctx
.ifbody(body -> jsonb.fromJson(body.text(), type.getType()))
.ifparam(values -> jsonb.fromJson(values.first(), type.getType()));
}
return ctx.next();
}
代码示例来源:origin: resteasy/Resteasy
@Override
public Object readFrom(Class<Object> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws java.io.IOException, javax.ws.rs.WebApplicationException {
Jsonb jsonb = getJsonb(type);
final EmptyCheckInputStream is = new EmptyCheckInputStream(entityStream);
try {
return jsonb.fromJson(is, genericType);
// If null is returned, considered to be empty stream
} catch (Throwable e)
{
if (is.isEmpty()) {
return null;
}
// detail text provided in logger message
throw new ProcessingException(Messages.MESSAGES.jsonBDeserializationError(e, e.getMessage()), e);
}
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
private T getT(String json) {
if (Objects.nonNull(json)) {
return JSONB.fromJson(json, clazz);
}
return null;
}
代码示例来源:origin: org.talend.sdk.component/component-runtime-manager
@Override
public Object decode(final byte[] value, final Type expectedType) {
if (!Class.class.isInstance(expectedType)) {
throw new IllegalArgumentException("Unsupported type: " + expectedType);
}
final Class<?> clazz = Class.class.cast(expectedType);
return jsonb.fromJson(new ByteArrayInputStream(value), clazz);
}
}
代码示例来源:origin: org.apache.johnzon/johnzon-jsonb
@Override
public T readFrom(final Class<T> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType,
final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException {
return getJsonb(type).fromJson(entityStream, genericType);
}
代码示例来源:origin: org.jnosql.diana/diana-driver-commons
@Override
public <T> T get(TypeSupplier<T> typeSupplier) throws NullPointerException, UnsupportedOperationException {
Objects.requireNonNull(typeSupplier, "typeSupplier is required");
return JSONB.fromJson(json, typeSupplier.get());
}
代码示例来源:origin: org.springframework.boot/spring-boot-test
@Override
protected T readObject(Reader reader, ResolvableType type) throws IOException {
return this.jsonb.fromJson(reader, type.getType());
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public Iterator<T> iterator() {
return StreamSupport.stream(queue.spliterator(), false)
.map(s -> JSONB.fromJson(s.toString(), clazz))
.collect(Collectors.toList()).iterator();
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public Iterator<T> iterator() {
return StreamSupport.stream(arrayList.spliterator(), false)
.map(s -> JSONB.fromJson(s.toString(), clazz))
.collect(toList()).iterator();
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public <T1> T1[] toArray(T1[] t1s) {
requireNonNull(t1s, "arrys is required");
return StreamSupport.stream(arrayList.spliterator(), false)
.map(s -> JSONB.fromJson(s.toString(), clazz))
.toArray(size -> t1s);
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public Object[] toArray() {
return StreamSupport.stream(arrayList.spliterator(), false)
.map(s -> JSONB.fromJson(s.toString(), clazz))
.toArray(Object[]::new);
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
static JsonObject toJson(Jsonb jsonb, Object value) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
jsonb.toJson(value, stream);
InputStream inputStream = new ByteArrayInputStream(stream.toByteArray());
Map<String, ?> map = jsonb.fromJson(inputStream, TYPE);
return JsonObject.from(map);
}
}
代码示例来源: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: br.com.jarch/jarch-bpm
public static TaskBean getTaskBpm(String taskId) {
Response response = getWebTarget()
.path(TASK)
.path(taskId)
.request(MediaType.APPLICATION_JSON_TYPE)
.get();
if (isStatusOk(response)) {
String json = response.readEntity(String.class);
return JsonbBuilder.create().fromJson(json, TaskBean.class);
}
return null;
}
代码示例来源:origin: br.com.jarch/jarch-bpmn
public static TaskBean getTaskBpm(String taskId) {
Response response = getWebTarget()
.path(TASK)
.path(taskId)
.request(MediaType.APPLICATION_JSON_TYPE)
.get();
if (isStatusOk(response)) {
String json = response.readEntity(String.class);
return JsonbBuilder.create().fromJson(json, TaskBean.class);
}
return null;
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public V put(K key, V value) {
Objects.requireNonNull(key, "key is required");
Objects.requireNonNull(value, "value is required");
JsonObject json = map.put(key.toString(), JsonObjectCouchbaseUtil.toJson(JSONB, value));
if (Objects.nonNull(json)) {
return JSONB.fromJson(json.toString(), valueClass);
}
return null;
}
代码示例来源:origin: org.jnosql.diana/couchbase-driver
@Override
public T set(int i, T t) {
requireNonNull(t, "object is required");
JsonObject json = arrayList.set(i, JsonObjectCouchbaseUtil.toJson(JSONB, t));
if (Objects.nonNull(json)) {
return JSONB.fromJson(json.toString(), clazz);
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!