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


Java JsonFlattener类代码示例

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


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

示例1: process

import com.github.wnameless.json.flattener.JsonFlattener; //导入依赖的package包/类
@Override
public String process(JsonNode jsonNode) throws JsonProcessingException {
  final StringBuilder builder = new StringBuilder();
  if(null != jsonNode){
    final String jsonText = MAPPER.writeValueAsString(jsonNode);
    final Map<String, Object>  flatMap = JsonFlattener.flattenAsMap(jsonText);
    final List<String> header = createHeader(flatMap);
   
    header.forEach(h -> {
      builder.append(h);
      builder.append("\t");
    });
    
    builder.replace(builder.lastIndexOf("\t"), builder.lastIndexOf("\t") + 1, "\n");
    for (final Iterator<String> iterator = flatMap.keySet().iterator(); iterator.hasNext(); ) {
      for(int i = 0; i < header.size(); i++){
        builder.append(flatMap.get(iterator.next()));
        builder.append("\t");
      }
      builder.replace(builder.lastIndexOf("\t"), builder.lastIndexOf("\t") + 1, "\n");
    }
  }
  return builder.toString();
}
 
开发者ID:sanjuthomas,项目名称:zeppelin-marklogic-interpreter,代码行数:25,代码来源:CollectionProcessor.java

示例2: putAsJson

import com.github.wnameless.json.flattener.JsonFlattener; //导入依赖的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

示例3: testGetAndPut

import com.github.wnameless.json.flattener.JsonFlattener; //导入依赖的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


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