本文整理了Java中org.eclipse.ditto.json.JsonObject
类的一些代码示例,展示了JsonObject
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonObject
类的具体详情如下:
包路径:org.eclipse.ditto.json.JsonObject
类名称:JsonObject
[英]Represents a JSON object. A JSON object is a set of key-value-pairs with unique keys.
Implementations of this interface are required to be immutable!
[中]表示JSON对象。JSON对象是一组具有唯一键的键值对。
此接口的实现要求是不可变的
代码示例来源:origin: org.eclipse.ditto/ditto-model-base
/**
* Sets message, description and link from a JSON object of it has matching fields with valid values.
*
* @param jsonObject The JSON object to read from.
* @throws NullPointerException if {@code jsonObject} is {@code null}.
*/
public DittoRuntimeExceptionBuilder<T> loadJson(final JsonObject jsonObject) {
jsonObject.getValue(MESSAGE).ifPresent(this::message);
jsonObject.getValue(DESCRIPTION).ifPresent(this::description);
jsonObject.getValue(HREF).map(URI::create).ifPresent(this::href);
return this;
}
代码示例来源:origin: org.eclipse.ditto/ditto-model-things
@Override
public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) {
return wrapped.getValueOrThrow(fieldDefinition);
}
代码示例来源:origin: org.eclipse.ditto/ditto-model-things
@Override
public JsonObject get(final JsonPointer pointer) {
return wrapped.get(pointer);
}
代码示例来源:origin: eclipse/ditto
private static JsonObject renameField(final CharSequence oldFieldName, final CharSequence newFieldName,
final JsonObject jsonObject) {
return jsonObject.getValue(oldFieldName)
.map(value -> jsonObject.setValue(newFieldName, value))
.orElse(jsonObject);
}
代码示例来源:origin: eclipse/ditto
/**
* A "payload" object was wrapping the events payload until the introduction of "cr-commands 1.0.0". This field has
* to be used as fallback for already persisted events with "things-model" < 3.0.0. Removing this workaround is
* possible if we are sure that no "old" events are ever loaded again!
*/
private static JsonObject migratePayload(final JsonObject jsonObject) {
return jsonObject.getValue(PAYLOAD)
.map(obj -> jsonObject.remove(PAYLOAD.getPointer()).setAll(obj))
.orElse(jsonObject);
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-connectivity-messaging
private static boolean needsSourceFilterMigration(final JsonObject connectionJsonObject) {
final Optional<JsonArray> sources = connectionJsonObject.getValue(Connection.JsonFields.SOURCES);
return sources.isPresent() && sources.get().stream().filter(JsonValue::isObject)
.map(JsonValue::asObject).anyMatch(source -> source.contains("filters"));
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-thingsearch-persistence
private static void handleObject(final String path, final JsonValue value, final List<Document> flatAttributes) {
final JsonObject jsonObject = value.asObject();
jsonObject.getKeys().forEach(key -> {
final String newPath = path + PersistenceConstants.SLASH + key;
final JsonValue innerValue = jsonObject.getValue(key).orElse(null);
toFlatAttributesList(newPath, innerValue, flatAttributes);
});
}
代码示例来源:origin: org.eclipse.ditto/ditto-model-connectivity
/**
* Creates a new {@code MappingContext} object from the specified JSON object.
*
* @param jsonObject a JSON object which provides the data for the MappingContext to be created.
* @return a new MappingContext which is initialised with the extracted data from {@code jsonObject}.
* @throws NullPointerException if {@code jsonObject} is {@code null}.
* @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object.
*/
public static MappingContext fromJson(final JsonObject jsonObject) {
final String mappingEngine = jsonObject.getValueOrThrow(JsonFields.MAPPING_ENGINE);
final Map<String, String> options = jsonObject.getValueOrThrow(JsonFields.OPTIONS).stream()
.collect(Collectors.toMap(
e -> e.getKey().toString(),
e -> e.getValue().isString() ? e.getValue().asString() : e.getValue().toString())
);
return of(mappingEngine, options);
}
代码示例来源: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: org.eclipse.ditto/ditto-model-things
@Override
public Stream<JsonField> stream() {
return wrapped.stream();
}
代码示例来源:origin: org.eclipse.ditto/ditto-model-things
@Override
public boolean contains(final CharSequence key) {
return wrapped.contains(key);
}
代码示例来源:origin: eclipse/ditto
private static Optional<Policy> getInlinedOrDefaultPolicyForCreateThing(final CreateThing createThing) {
final Optional<JsonObject> initialPolicy = createThing.getInitialPolicy();
if (initialPolicy.isPresent()) {
final JsonObject policyJson = initialPolicy.get();
final JsonObjectBuilder policyJsonBuilder = policyJson.toBuilder();
final Thing thing = createThing.getThing();
if (thing.getPolicyId().isPresent() || !policyJson.contains(Policy.JsonFields.ID.getPointer())) {
final String policyId = thing.getPolicyId().orElse(createThing.getThingId());
policyJsonBuilder.set(Policy.JsonFields.ID, policyId);
}
return Optional.of(PoliciesModelFactory.newPolicy(policyJsonBuilder.build()));
} else {
return getDefaultPolicy(createThing.getDittoHeaders().getAuthorizationContext(), createThing.getThingId());
}
}
代码示例来源:origin: eclipse/ditto
private static boolean needsSourceFilterMigration(final JsonObject connectionJsonObject) {
final Optional<JsonArray> sources = connectionJsonObject.getValue(Connection.JsonFields.SOURCES);
return sources.isPresent() && sources.get().stream().filter(JsonValue::isObject)
.map(JsonValue::asObject).anyMatch(source -> source.contains("filters"));
}
代码示例来源:origin: eclipse/ditto
@SuppressWarnings("squid:CallToDeprecatedMethod")
private static JsonObject migrateId(final JsonObject jsonObject) {
return jsonObject.getValue(Event.JsonFields.ID)
.map(name -> name.replaceFirst("thing", ""))
.map(Introspector::decapitalize)
.map(name -> ThingEvent.TYPE_PREFIX + name)
.map(JsonValue::of)
.map(type -> jsonObject.setValue(Event.JsonFields.TYPE.getPointer(), type))
.orElse(jsonObject);
}
代码示例来源: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: org.eclipse.ditto/ditto-model-things
@Override
public Stream<JsonField> stream() {
return wrapped.stream();
}
代码示例来源:origin: org.eclipse.ditto/ditto-model-things
@Override
public boolean contains(final CharSequence key) {
return wrapped.contains(key);
}
代码示例来源:origin: eclipse/ditto
private static Thing createThingForPost(final String jsonString) {
final JsonObject inputJson = wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString));
if (inputJson.contains(Thing.JsonFields.ID.getPointer())) {
throw ThingIdNotExplicitlySettableException.newBuilder(true).build();
}
final String thingId = ThingBuilder.generateRandomThingId();
final JsonObjectBuilder outputJsonBuilder = inputJson.toBuilder();
outputJsonBuilder.set(Thing.JsonFields.ID.getPointer(), thingId);
return ThingsModelFactory.newThingBuilder(outputJsonBuilder.build())
.setId(thingId)
.build();
}
代码示例来源:origin: org.eclipse.ditto/ditto-signals-commands-devops
@Override
protected String resolveType(final JsonObject jsonObject) {
return jsonObject.getValueOrThrow(DevOpsCommandResponse.JsonFields.TYPE);
}
代码示例来源:origin: eclipse/ditto
/**
* Sets message, description and link from a JSON object of it has matching fields with valid values.
*
* @param jsonObject The JSON object to read from.
* @throws NullPointerException if {@code jsonObject} is {@code null}.
*/
public DittoRuntimeExceptionBuilder<T> loadJson(final JsonObject jsonObject) {
jsonObject.getValue(MESSAGE).ifPresent(this::message);
jsonObject.getValue(DESCRIPTION).ifPresent(this::description);
jsonObject.getValue(HREF).map(URI::create).ifPresent(this::href);
return this;
}
内容来源于网络,如有侵权,请联系作者删除!