当前位置: 首页>>代码示例>>Java>>正文


Java FlattenMode类代码示例

本文整理汇总了Java中com.github.wnameless.json.flattener.FlattenMode的典型用法代码示例。如果您正苦于以下问题:Java FlattenMode类的具体用法?Java FlattenMode怎么用?Java FlattenMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FlattenMode类属于com.github.wnameless.json.flattener包,在下文中一共展示了FlattenMode类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: putAsJson

import com.github.wnameless.json.flattener.FlattenMode; //导入依赖的package包/类
/**
 * Puts the content of the Json recursively from the specified <i>path</i>
 * @param path root path (i.e. /path1/path2)
 * @param data JsonNode
 * @param etcdClient EtcdClient
 */
public static void putAsJson(String path, JsonNode data, EtcdClient etcdClient)
        throws IOException, EtcdAuthenticationException, TimeoutException, EtcdException {

  Map<String, Object> flattened = new JsonFlattener(EtcdUtil.jsonToString(data))
          .withFlattenMode(FlattenMode.MONGODB)
          .withSeparator('/')
          .flattenAsMap();

  // clean previous data and replace it with new json structure
  try {
    etcdClient.delete(path).recursive().send().get();
  } catch (EtcdException e) {
    // interrupt always except when the previous key didn't exist
    if (EtcdErrorCode.KeyNotFound != e.errorCode) {
      throw e;
    }
  }

  // iterate over every flattened key and build the structure in etcd
  for (Map.Entry<String, Object> entry : flattened.entrySet()) {
    etcdClient.put(path + "/" + entry.getKey(), String.valueOf(entry.getValue())).send().get();
  }
}
 
开发者ID:jurmous,项目名称:etcd4j,代码行数:30,代码来源:EtcdUtil.java

示例2: dotNotationToStandardJson

import com.github.wnameless.json.flattener.FlattenMode; //导入依赖的package包/类
/**
 * Transforms etcd format (in dot notation) to a standard Json (with arrays and primitive types)
 * @param etcdJson from etcd
 * @return standardized Json
 * @throws IOException
 */
private static JsonNode dotNotationToStandardJson(JsonNode etcdJson) throws IOException {
  if (!etcdJson.isValueNode()) {
    String unflattened = new JsonUnflattener(jsonToString(flattenJson(etcdJson, "")))
            .withFlattenMode(FlattenMode.MONGODB)
            .withKeyTransformer(new KeyTransformer() {
              @Override
              public String transform(String s) {
                return s.replaceAll("__DOT__", "\\.");
              }
            })
            .unflatten();
    return mapper.readTree(unflattened);
  } else {
    return etcdJson;
  }
}
 
开发者ID:jurmous,项目名称:etcd4j,代码行数:23,代码来源:EtcdUtil.java

示例3: testGetAndPut

import com.github.wnameless.json.flattener.FlattenMode; //导入依赖的package包/类
@Test
public void testGetAndPut() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    EtcdNettyConfig config = new EtcdNettyConfig();
    EtcdNettyClient nettyClient = new EtcdNettyClient(config, URI.create("http://localhost:4001"));
    config.setMaxFrameSize(1024 * 1024); // Desired max size
    EtcdClient client = new EtcdClient(nettyClient);

    File testJson = new File("src/test/resources/test_data.json");
    JsonNode original = mapper.readTree(testJson);

    JsonNode fromEtcd = EtcdUtil.getAsJson("/etcd4j_test", client);

    // flatten both and compare
    Map<String, Object> rootFlat = new JsonFlattener(EtcdUtil.jsonToString(original))
            .withFlattenMode(FlattenMode.MONGODB)
            .withSeparator('/')
            .flattenAsMap();

    Map<String, Object> testFlat = new JsonFlattener(EtcdUtil.jsonToString(fromEtcd))
            .withFlattenMode(FlattenMode.MONGODB)
            .withSeparator('/')
            .flattenAsMap();

    assertEquals(rootFlat.size(), testFlat.size());
    for (Map.Entry<String, Object> entry : rootFlat.entrySet()) {
        assertNotNull(testFlat.get(entry.getKey()));
    }
}
 
开发者ID:jurmous,项目名称:etcd4j,代码行数:30,代码来源:EtcdJsonTest.java

示例4: withFlattenMode

import com.github.wnameless.json.flattener.FlattenMode; //导入依赖的package包/类
/**
 * A fluent setter to setup a mode of the {@link JsonUnflattener}.
 * 
 * @param flattenMode
 *          a {@link FlattenMode}
 * @return this {@link JsonUnflattener}
 */
public JsonUnflattener withFlattenMode(FlattenMode flattenMode) {
  this.flattenMode = notNull(flattenMode);
  return this;
}
 
开发者ID:wnameless,项目名称:json-flattener,代码行数:12,代码来源:JsonUnflattener.java


注:本文中的com.github.wnameless.json.flattener.FlattenMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。