本文整理了Java中org.eclipse.ditto.json.JsonObject.newBuilder()
方法的一些代码示例,展示了JsonObject.newBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonObject.newBuilder()
方法的具体详情如下:
包路径:org.eclipse.ditto.json.JsonObject
类名称:JsonObject
方法名:newBuilder
[英]Returns a new mutable builder with a fluent API for a JsonObject.
[中]返回一个新的可变生成器,其中包含JsonObject的流畅API。
代码示例来源:origin: eclipse/ditto
private String encodeCorrelationId(final DittoHeaders dittoHeaders) {
return JsonObject.newBuilder()
.set(BATCH_ID_FIELD, batchId)
.set(RANDOM_FIELD, UUID.randomUUID().toString())
.set(ORIGINAL_CORRELATION_ID, dittoHeaders.getCorrelationId().orElse(UUID.randomUUID().toString()))
.build()
.toString();
}
代码示例来源:origin: eclipse/ditto
@Override
@Nonnull
public JsonObject toJson(@Nonnull final JsonSchemaVersion schemaVersion,
@Nonnull final Predicate<JsonField> thePredicate) {
final Predicate<JsonField> predicate = schemaVersion.and(thePredicate);
final JsonObjectBuilder jsonObjectBuilder = JsonObject.newBuilder();
jsonObjectBuilder.set(JSON_STREAMING_TYPE, streamingType.getDistributedPubSubTopic(), predicate);
jsonObjectBuilder.set(JSON_SUBSCRIBED, subscribed, predicate);
return jsonObjectBuilder.build();
}
代码示例来源:origin: eclipse/ditto
@Override
public void toBinary(final Object object, final ByteBuffer buf) {
if (object instanceof Jsonifiable) {
final JsonObjectBuilder jsonObjectBuilder = JsonObject.newBuilder();
final DittoHeaders dittoHeaders = getDittoHeadersOrEmpty(object);
jsonObjectBuilder.set(JSON_DITTO_HEADERS, dittoHeaders.toJson());
final JsonValue jsonValue;
if (object instanceof Jsonifiable.WithPredicate) {
final JsonSchemaVersion schemaVersion =
dittoHeaders.getSchemaVersion().orElse(JsonSchemaVersion.LATEST);
jsonValue = ((Jsonifiable.WithPredicate) object).toJson(schemaVersion, FieldType.regularOrSpecial());
} else {
jsonValue = ((Jsonifiable) object).toJson();
}
jsonObjectBuilder.set(JSON_PAYLOAD, jsonValue);
buf.put(UTF8_CHARSET.encode(jsonObjectBuilder.build()
.toString())
);
} else {
LOG.error("Could not serialize class <{}> as it does not implement <{}>!", object.getClass(),
Jsonifiable.WithPredicate.class);
final String error = new NotSerializableException(object.getClass().getName()).getMessage();
buf.put(UTF8_CHARSET.encode(error));
}
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-cluster
@Override
public void toBinary(final Object object, final ByteBuffer buf) {
if (object instanceof Jsonifiable) {
final JsonObjectBuilder jsonObjectBuilder = JsonObject.newBuilder();
final DittoHeaders dittoHeaders = getDittoHeadersOrEmpty(object);
jsonObjectBuilder.set(JSON_DITTO_HEADERS, dittoHeaders.toJson());
final JsonValue jsonValue;
if (object instanceof Jsonifiable.WithPredicate) {
final JsonSchemaVersion schemaVersion =
dittoHeaders.getSchemaVersion().orElse(JsonSchemaVersion.LATEST);
jsonValue = ((Jsonifiable.WithPredicate) object).toJson(schemaVersion, FieldType.regularOrSpecial());
} else {
jsonValue = ((Jsonifiable) object).toJson();
}
jsonObjectBuilder.set(JSON_PAYLOAD, jsonValue);
buf.put(UTF8_CHARSET.encode(jsonObjectBuilder.build()
.toString())
);
} else {
LOG.error("Could not serialize class <{}> as it does not implement <{}>!", object.getClass(),
Jsonifiable.WithPredicate.class);
final String error = new NotSerializableException(object.getClass().getName()).getMessage();
buf.put(UTF8_CHARSET.encode(error));
}
}
代码示例来源:origin: org.eclipse.ditto/ditto-signals-commands-connectivity
private JsonObject buildJsonRepresentation(final Predicate<JsonField> predicate) {
final JsonObjectBuilder builder = JsonObject.newBuilder();
aggregatedResponses.forEach(cmdR ->
builder.set("/" + calculateSource(cmdR), cmdR.toJson(predicate)));
if (builder.isEmpty()) {
return JsonFactory.nullObject();
} else {
return builder.build();
}
}
代码示例来源:origin: org.eclipse.ditto/ditto-signals-commands-devops
private static JsonObject buildJsonRepresentation(final List<CommandResponse<?>> commandResponses,
final DittoHeaders dittoHeaders) {
final JsonObjectBuilder builder = JsonObject.newBuilder();
commandResponses.forEach(cmdR ->
builder.set("/" + calculateServiceName(cmdR) + "/" + calculateInstance(cmdR),
cmdR.toJson(dittoHeaders.getSchemaVersion().orElse(JsonSchemaVersion.LATEST))));
if (builder.isEmpty()) {
return JsonFactory.nullObject();
} else {
return builder.build();
}
}
代码示例来源:origin: eclipse/ditto
private JsonObject buildJsonRepresentation(final Predicate<JsonField> predicate) {
final JsonObjectBuilder builder = JsonObject.newBuilder();
aggregatedResponses.forEach(cmdR ->
builder.set("/" + calculateSource(cmdR), cmdR.toJson(predicate)));
if (builder.isEmpty()) {
return JsonFactory.nullObject();
} else {
return builder.build();
}
}
代码示例来源:origin: eclipse/ditto
log.error(throwable, "Could not determine 'ShardRegionState' for shard region <{}>",
shardRegionName);
return RetrieveStatisticsDetailsResponse.of(JsonObject.newBuilder()
.set(shardRegionName, JsonFactory.newObject())
.build(),
.collect(JsonCollectors.fieldsToObject());
final JsonObject thingNamespacesStats = JsonObject.newBuilder()
.set(shardRegionName, namespaceStats)
.build();
log.warning("Unexpected answer to " +
"'ShardRegion.getShardRegionStateInstance()': {}", result);
return RetrieveStatisticsDetailsResponse.of(JsonObject.newBuilder()
.set(shardRegionName, JsonFactory.newObject())
.build(),
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-cluster
log.error(throwable, "Could not determine 'ShardRegionState' for shard region <{}>",
shardRegionName);
return RetrieveStatisticsDetailsResponse.of(JsonObject.newBuilder()
.set(shardRegionName, JsonFactory.newObject())
.build(),
.collect(JsonCollectors.fieldsToObject());
final JsonObject thingNamespacesStats = JsonObject.newBuilder()
.set(shardRegionName, namespaceStats)
.build();
log.warning("Unexpected answer to " +
"'ShardRegion.getShardRegionStateInstance()': {}", result);
return RetrieveStatisticsDetailsResponse.of(JsonObject.newBuilder()
.set(shardRegionName, JsonFactory.newObject())
.build(),
代码示例来源:origin: eclipse/ditto
return JsonObject.newBuilder()
.set(addressString, throwable.getMessage()).build();
} else {
return ((SimpleCommandResponse) o).getPayload()
.map(JsonValue::asObject)
.orElse(JsonObject.newBuilder().build());
.map(JsonValue::asString)
.orElse("?");
final JsonObjectBuilder subBuilder = JsonObject.newBuilder();
subStatusObj.forEach(subBuilder::set);
if (roleStatusBuilder.build().contains(key)) {
JsonObject.newBuilder().set(role, rolesStatus).build());
代码示例来源:origin: org.eclipse.ditto/ditto-signals-base
@Override
public JsonObject toJson() {
return JsonObject.newBuilder()
.set(JSON_ID, id)
.set(JSON_TYPE, type)
.set(JSON_MESSAGE, message)
.set(JSON_DITTO_HEADERS, dittoHeaders.toJson())
.build();
}
代码示例来源:origin: eclipse/ditto
@Override
public JsonObject toJson() {
return JsonObject.newBuilder()
.set(JSON_ID, id)
.set(JSON_TYPE, type)
.set(JSON_MESSAGE, message)
.set(JSON_DITTO_HEADERS, dittoHeaders.toJson())
.build();
}
代码示例来源:origin: eclipse/ditto
private static JsonObject buildJsonRepresentation(final List<CommandResponse<?>> commandResponses,
final DittoHeaders dittoHeaders) {
final JsonObjectBuilder builder = JsonObject.newBuilder();
int i = 0;
for (final CommandResponse<?> cmdR : commandResponses) {
builder.set("/" + calculateServiceName(cmdR) + "/" + calculateInstance(cmdR, i++),
cmdR.toJson(dittoHeaders.getSchemaVersion().orElse(JsonSchemaVersion.LATEST)));
}
if (builder.isEmpty()) {
return JsonFactory.nullObject();
} else {
return builder.build();
}
}
代码示例来源:origin: bsinno/iot-things-examples
/**
* Create a {@code Thing} with the counter {@code Feature}. Blocks until Thing has been created.
*
* @return a handle for the counter.
*/
public FeatureHandle createThingWithCounter() {
final Thing thing = Thing.newBuilder() //
.setId(thingId) //
.setFeature(Feature.newBuilder() //
.properties(JsonObject.newBuilder() //
.set(COUNTER_VALUE, 0) //
.build()) //
.withId(COUNTER) //
.build()) //
.build();
FeatureHandle featureHandle = null;
try {
featureHandle = twin.create(thing) //
.thenApply(created -> twin.forFeature(thingId, COUNTER)) //
.get(TIMEOUT, TimeUnit.SECONDS);
LOGGER.info("Thing with ID '{}' created.", thingId);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.error(e.getMessage());
}
return featureHandle;
}
代码示例来源:origin: org.eclipse.ditto/ditto-protocol-adapter
@Override
public JsonObject toJson() {
final JsonObjectBuilder jsonObjectBuilder = JsonObject.newBuilder();
jsonObjectBuilder.set(JsonFields.PATH, path.toString());
if (null != value) {
jsonObjectBuilder.set(JsonFields.VALUE, value);
}
if (null != status) {
jsonObjectBuilder.set(JsonFields.STATUS, status.toInt());
}
if (null != revision) {
jsonObjectBuilder.set(JsonFields.REVISION, revision);
}
if (null != timestamp) {
jsonObjectBuilder.set(JsonFields.TIMESTAMP, timestamp.toString());
}
if (null != fields) {
jsonObjectBuilder.set(JsonFields.FIELDS, fields.toString());
}
return jsonObjectBuilder.build();
}
代码示例来源:origin: eclipse/ditto
@Override
public JsonObject toJson() {
final JsonObjectBuilder jsonObjectBuilder = JsonObject.newBuilder();
jsonObjectBuilder.set(JsonFields.PATH, path.toString());
if (null != value) {
jsonObjectBuilder.set(JsonFields.VALUE, value);
}
if (null != status) {
jsonObjectBuilder.set(JsonFields.STATUS, status.toInt());
}
if (null != revision) {
jsonObjectBuilder.set(JsonFields.REVISION, revision);
}
if (null != timestamp) {
jsonObjectBuilder.set(JsonFields.TIMESTAMP, timestamp.toString());
}
if (null != fields) {
jsonObjectBuilder.set(JsonFields.FIELDS, fields.toString());
}
return jsonObjectBuilder.build();
}
代码示例来源:origin: eclipse/ditto
return StatusInfo.fromStatus(StatusInfo.Status.UP);
} else {
final JsonObject missingRolesJson = JsonObject.newBuilder()
.set(JSON_KEY_MISSING_ROLES, healthClusterRolesExpected.stream()
.map(JsonValue::of)
代码示例来源:origin: eclipse/ditto
@SuppressWarnings("unchecked")
private static JsonObject filterByTrie(final JsonObject self, final JsonFieldSelectorTrie trie) {
if (trie.isEmpty()) {
return self;
}
final JsonObjectBuilder builder = JsonObject.newBuilder();
for (final JsonKey key : trie.getKeys()) {
self.getField(key).ifPresent(child -> {
final JsonValue childValue = child.getValue();
final JsonValue filteredChildValue = childValue.isObject()
? filterByTrie(childValue.asObject(), trie.descend(key))
: childValue;
final Optional<JsonFieldDefinition> childFieldDefinition = child.getDefinition();
if (childFieldDefinition.isPresent()) {
builder.set(childFieldDefinition.get(), filteredChildValue);
} else {
builder.set(key, filteredChildValue);
}
});
}
return builder.build();
}
代码示例来源:origin: eclipse/ditto
private Graph<SourceShape<QueryThingsResponse>, NotUsed> retrieveThingsForIds(final ResultList<String> thingIds,
final QueryThings queryThings) {
final Graph<SourceShape<QueryThingsResponse>, NotUsed> result;
final DittoHeaders dittoHeaders = queryThings.getDittoHeaders();
final Optional<String> correlationIdOpt = dittoHeaders.getCorrelationId();
LogUtil.enhanceLogWithCorrelationId(log, correlationIdOpt);
if (thingIds.isEmpty()) {
result = Source.<QueryThingsResponse>single(QueryThingsResponse.of(SearchModelFactory.emptySearchResult(), dittoHeaders));
} else {
// only respond with the determined "thingIds", the lookup of the things is done in gateway:
final JsonArray items = thingIds.stream()
.map(JsonValue::of)
.map(jsonStr -> JsonObject.newBuilder()
.set(Thing.JsonFields.ID.getPointer(), jsonStr)
.build()
)
.collect(JsonCollectors.valuesToArray());
final SearchResult searchResult = SearchModelFactory.newSearchResult(items, thingIds.nextPageOffset());
result = Source.<QueryThingsResponse>single(QueryThingsResponse.of(searchResult, dittoHeaders));
}
return result;
}
代码示例来源:origin: eclipse/ditto
private Route handleSudoCountThingsPerRequest(final RequestContext ctx, final SudoCountThings command) {
final CompletableFuture<HttpResponse> httpResponseFuture = new CompletableFuture<>();
Source.single(command)
.to(Sink.actorRef(createHttpPerRequestActor(ctx, httpResponseFuture),
HttpRequestActor.COMPLETE_MESSAGE))
.run(materializer);
final CompletionStage<HttpResponse> allThingsCountHttpResponse = Source.fromCompletionStage(httpResponseFuture)
.flatMapConcat(httpResponse -> httpResponse.entity().getDataBytes())
.fold(ByteString.empty(), ByteString::concat)
.map(ByteString::utf8String)
.map(Integer::valueOf)
.map(count -> JsonObject.newBuilder().set("allThingsCount", count).build())
.map(jsonObject -> HttpResponse.create()
.withEntity(ContentTypes.APPLICATION_JSON, ByteString.fromString(jsonObject.toString()))
.withStatus(HttpStatusCode.OK.toInt()))
.runWith(Sink.head(), materializer);
return completeWithFuture(allThingsCountHttpResponse);
}
内容来源于网络,如有侵权,请联系作者删除!