org.eclipse.ditto.json.JsonObject.getValue()方法的使用及代码示例

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

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

JsonObject.getValue介绍

[英]Returns the value which is associated with the specified key. This method is similar to #get(JsonPointer)however it does not maintain any hierarchy but returns simply the value. If, for example, on the following JSON object

{ 
"thingId": "myThing", 
"attributes": { 
"someAttr": { 
"subsel": 42 
}, 
"anotherAttr": "baz" 
} 
}

this method is called with key "attributes/someAttr/subsel" an empty Optional is returned. Is the key "thingId" used instead the returned Optional would contain "myThing". If the specified key is empty or "/" this object reference is returned within the result.
[中]返回与指定键关联的值。此方法类似于#get(JsonPointer),但它不维护任何层次结构,只返回值。例如,如果在以下JSON对象上

{ 
"thingId": "myThing", 
"attributes": { 
"someAttr": { 
"subsel": 42 
}, 
"anotherAttr": "baz" 
} 
}

使用键“attributes/someAttr/subsel”调用此方法,则返回一个空的可选值。是否使用了键“thingId”,而返回的可选项将包含“myThing”。如果指定的键为空或“/”则在结果中返回此对象引用。

代码示例

代码示例来源: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: 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;
}

代码示例来源:origin: org.eclipse.ditto/ditto-services-policies-persistence

@SuppressWarnings("squid:CallToDeprecatedMethod")
private JsonObject migrateComplex(final JsonObject jsonObject) {
  return jsonObject.getValue(Event.JsonFields.ID)
      .map(migrationMappings::get)
      .map(migration -> migration.apply(jsonObject))
      .orElse(jsonObject);
}

代码示例来源:origin: eclipse/ditto

@SuppressWarnings("squid:CallToDeprecatedMethod")
private JsonObject migrateComplex(final JsonObject jsonObject) {
  return jsonObject.getValue(Event.JsonFields.ID)
      .map(migrationMappings::get)
      .map(migration -> migration.apply(jsonObject))
      .orElse(jsonObject);
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-connectivity

static ClientCertificateCredentials fromJson(final JsonObject jsonObject) {
  final Builder builder = newBuilder();
  jsonObject.getValue(JsonFields.CLIENT_CERTIFICATE).ifPresent(builder::clientCertificate);
  jsonObject.getValue(JsonFields.CLIENT_KEY).ifPresent(builder::clientKey);
  return builder.build();
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-connectivity

private static Set<String> getTags(final JsonObject jsonObject) {
  return jsonObject.getValue(JsonFields.TAGS)
      .map(array -> array.stream()
          .filter(JsonValue::isString)
          .map(JsonValue::asString)
          .collect(Collectors.toSet()))
      .orElse(Collections.emptySet());
}

代码示例来源: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

private ImmutableJsonWebToken(final String authorizationString) {
  super(authorizationString);
  authorizationSubjects = getBody().getValue(JsonFields.USER_ID)
      .map(Collections::singletonList)
      .orElse(Collections.emptyList());
}

代码示例来源:origin: org.eclipse.ditto/ditto-model-connectivity

private static Set<Target> getTargets(final JsonObject jsonObject, final ConnectionType type) {
  return jsonObject.getValue(JsonFields.TARGETS)
      .map(array -> array.stream()
          .filter(JsonValue::isObject)
          .map(JsonValue::asObject)
          .map(valueAsObject -> ConnectivityModelFactory.targetFromJson(valueAsObject, type))
          .collect(Collectors.toSet()))
      .orElse(Collections.emptySet());
}

代码示例来源:origin: eclipse/ditto

private static Set<Target> getTargets(final JsonObject jsonObject, final ConnectionType type) {
  return jsonObject.getValue(JsonFields.TARGETS)
      .map(array -> array.stream()
          .filter(JsonValue::isObject)
          .map(JsonValue::asObject)
          .map(valueAsObject -> ConnectivityModelFactory.targetFromJson(valueAsObject, type))
          .collect(Collectors.toSet()))
      .orElse(Collections.emptySet());
}

代码示例来源: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: 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-protocol-adapter

private static String policyIdOrPlaceholderForCreateThingFrom(final Adaptable adaptable) {
  return adaptable.getPayload().getValue()
      .map(JsonValue::asObject)
      .flatMap(o -> o.getValue(CreateThing.JSON_COPY_POLICY_FROM))
      .orElse(null);
}

代码示例来源:origin: eclipse/ditto

private static String getCopyPolicyFrom(final String jsonString) {
  final JsonObject inputJson = wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString));
  return inputJson.getValue(ModifyThing.JSON_COPY_POLICY_FROM)
      .orElse(null);
}

代码示例来源: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: 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-signals-commands-base

@Override
protected String resolveType(final JsonObject jsonObject) {
  final Supplier<String> command = () -> jsonObject.getValue(Command.JsonFields.ID)
      .map(cmd -> getTypePrefix() + cmd) // and transform to V2 format
      // fail if "command" also is not present
      .orElseThrow(() -> JsonMissingFieldException.newBuilder()
          .fieldName(Command.JsonFields.TYPE.getPointer().toString())
          .build());
  // if type was not present (was included in V2) take "command" instead
  return jsonObject.getValue(Command.JsonFields.TYPE).orElseGet(command);
}

代码示例来源:origin: eclipse/ditto

@Override
protected String resolveType(final JsonObject jsonObject) {
  final Supplier<String> command = () -> jsonObject.getValue(Command.JsonFields.ID)
      .map(cmd -> getTypePrefix() + cmd) // and transform to V2 format
      // fail if "command" also is not present
      .orElseThrow(() -> JsonMissingFieldException.newBuilder()
          .fieldName(Command.JsonFields.TYPE.getPointer().toString())
          .build());
  // if type was not present (was included in V2) take "command" instead
  return jsonObject.getValue(Command.JsonFields.TYPE).orElseGet(command);
}

代码示例来源:origin: eclipse/ditto

private static String getMessage(final JsonObject jsonObject) {
  return jsonObject.getValue(DittoJsonException.JsonFields.MESSAGE)
      .orElseThrow(() -> JsonMissingFieldException.newBuilder()
          .fieldName(DittoRuntimeException.JsonFields.MESSAGE.getPointer().toString()).build());
}

代码示例来源:origin: eclipse/ditto

private CommandResponse unfixCorrelationId(final CommandResponse response) {
  final String correlationId = response.getDittoHeaders()
      .getCorrelationId()
      .flatMap(s -> decodeCommandCorrelationId(s).getValue(ORIGINAL_CORRELATION_ID))
      .map(JsonValue::asString)
      .orElse(null);
  final DittoHeaders dittoHeaders = response.getDittoHeaders().toBuilder()
      .correlationId(correlationId)
      .build();
  return response.setDittoHeaders(dittoHeaders);
}

相关文章