com.couchbase.client.java.document.json.JsonObject.toMap()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(123)

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

JsonObject.toMap介绍

[英]Transforms the JsonObject into a Map. The resulting map is not backed by this JsonObject, and all sub-objects or sub-arrays ( JsonArray) are also recursively converted to maps and lists, respectively.
[中]将JsonObject转换为映射。这个JsonObject不支持生成的映射,所有子对象或子数组(JsonArray)也分别递归转换为映射和列表。

代码示例

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

@Override
public Session get(final Builder builder) {
 return Optional
   .ofNullable(bucket.getAndTouch(N1Q.qualifyId(SESSION, builder.sessionId()), expiry))
   .map(doc -> {
    Map session = doc.content().toMap();
    Long accessedAt = (Long) session.remove("_accessedAt");
    Long createdAt = (Long) session.remove("_createdAt");
    Long savedAt = (Long) session.remove("_savedAt");
    return builder
      .accessedAt(accessedAt)
      .createdAt(createdAt)
      .savedAt(savedAt)
      .set(session)
      .build();
   }).orElse(null);
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

/**
  * Converts a {@link JsonObject} list into a {@link CouchbaseQueryResult} so that it can
  * be {@link Stream}-ed and returned by the procedures
  * 
  * @param jsonObjects
  *          the {@link JsonObject} list to convert
  * @return the converted list in the form of a CouchbaseQueryResult
  */
 public static CouchbaseQueryResult convertToCouchbaseQueryResult(List<JsonObject> jsonObjects) {
  CouchbaseQueryResult result = null;
  if (jsonObjects != null && jsonObjects.size() > 0) {
   List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(jsonObjects.size());
   for (JsonObject jsonObject : jsonObjects) {
    list.add(jsonObject.toMap());
   }
   result = new CouchbaseQueryResult(list);
  }
  return result;
 }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

public CouchbaseJsonDocument(JsonDocument jsonDocument) {
 this.id = jsonDocument.id();
 this.expiry = jsonDocument.expiry();
 this.cas = jsonDocument.cas();
 this.mutationToken = CouchbaseUtils.convertMutationTokenToMap(jsonDocument.mutationToken());
 this.content = (jsonDocument.content() != null) ? this.content = jsonDocument.content().toMap()
   : new HashMap<String, Object>();
}

代码示例来源:origin: com.couchbase.client/java-client

@Override
  public void serialize(JsonObject value, JsonGenerator jgen,
             SerializerProvider provider) throws IOException {
    jgen.writeObject(value.toMap());
  }
}

代码示例来源:origin: com.couchbase.client/java-client

/**
 * Copies the content of the {@link JsonArray} into a new {@link List} and returns it.
 * Note that if the array contains sub-{@link JsonObject} or {@link JsonArray}, they
 * will recursively be converted to {@link Map} and {@link List}, respectively.
 *
 * @return the content of the {@link JsonArray} in a new {@link List}.
 */
public List<Object> toList() {
  List<Object> copy = new ArrayList<Object>(content.size());
  for (Object o : content) {
    if (o instanceof JsonObject) {
      copy.add(((JsonObject) o).toMap());
    } else if (o instanceof JsonArray) {
      copy.add(((JsonArray) o).toList());
    } else {
      copy.add(o);
    }
  }
  return copy;
}

代码示例来源:origin: com.couchbase.client/java-client

/**
 * Transforms the {@link JsonObject} into a {@link Map}. The resulting
 * map is not backed by this {@link JsonObject}, and all sub-objects or
 * sub-arrays ({@link JsonArray}) are also recursively converted to
 * maps and lists, respectively.
 *
 * @return the content copied as a {@link Map}.
 */
public Map<String, Object> toMap() {
  Map<String, Object> copy = new HashMap<String, Object>(content.size());
  for (Map.Entry<String, Object> entry : content.entrySet()) {
    Object content = entry.getValue();
    if (content instanceof JsonObject) {
      copy.put(entry.getKey(), ((JsonObject) content).toMap());
    } else if (content instanceof JsonArray) {
      copy.put(entry.getKey(), ((JsonArray) content).toList());
    } else {
      copy.put(entry.getKey(), content);
    }
  }
  return copy;
}

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

static List<DocumentEntity> convert(Collection<String> keys, Bucket bucket) {
  return keys
      .stream()
      .map(bucket::get)
      .filter(Objects::nonNull)
      .map(j -> {
        List<Document> documents = toDocuments(j.content().toMap());
        return DocumentEntity.of(j.id().split(SPLIT_KEY)[0], documents);
      })
      .collect(Collectors.toList());
}

代码示例来源:origin: com.couchbase.client/java-client

@Override
public Set<Entry<String, V>> entrySet() {
  return new CouchbaseEntrySet((Map<String, V>) bucket.get(id).content().toMap());
}

相关文章