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


Java ObjectMapper.readTree方法代码示例

本文整理汇总了Java中org.codehaus.jackson.map.ObjectMapper.readTree方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.readTree方法的具体用法?Java ObjectMapper.readTree怎么用?Java ObjectMapper.readTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jackson.map.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.readTree方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialize

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
public StatePair deserialize(JsonParser parser, 
                             DeserializationContext context)
throws IOException, JsonProcessingException {
  ObjectMapper mapper = (ObjectMapper) parser.getCodec();
  // set the state-pair object tree
  ObjectNode statePairObject = (ObjectNode) mapper.readTree(parser);
  Class<?> stateClass = null;
  
  try {
    stateClass = 
      Class.forName(statePairObject.get("className").getTextValue().trim());
  } catch (ClassNotFoundException cnfe) {
    throw new RuntimeException("Invalid classname!", cnfe);
  }
  
  String stateJsonString = statePairObject.get("state").toString();
  State state = (State) mapper.readValue(stateJsonString, stateClass);
  
  return new StatePair(state);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:StateDeserializer.java

示例2: search

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public QAService.Data search(String question) throws Exception {
    QAService.Data data = new QAService.Data();
    String response = makeRequest(question);
    if(response != null) {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode rootNode = mapper.readTree(response);
        JsonNode answers = mapper.readTree(rootNode.findValue("questions").get(0).get("question").get("answers").getTextValue());

        if (answers != null) {
            JsonNode bindings = answers.get("results").get("bindings");
            for(JsonNode binding : bindings) {
                Iterator<Map.Entry<String, JsonNode>> nodes = binding.getFields();
                while (nodes.hasNext()) {
                    Map.Entry<String, JsonNode> entry = nodes.next();
                    JsonNode value = entry.getValue();
                    switch(value.get("type").getTextValue()) {
                        case "uri":
                            data.addURI(value.get("value").getTextValue());
                            break;
                        case "typed-literal":
                            data.addLiteral(value.get("value").getTextValue());
                            break;
                    }
                }
            }
        }
    }
    return data;
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:30,代码来源:QANARY.java

示例3: parseJson

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
 *  Parse the json of flow_data field from execution_flows. Use recursion to handle the nested case.
 * @param flowJson
 * @param flowExecId
 * @return
 * @throws IOException
 */
public List<AzkabanJobExecRecord> parseJson(String flowJson, long flowExecId)
  throws IOException {

  ObjectMapper mapper = new ObjectMapper();
  JsonNode wholeFlow = mapper.readTree(flowJson);
  JsonNode allJobs = wholeFlow.get("nodes");
  String flowPath = wholeFlow.get("projectName").asText() + ":" + wholeFlow.get("flowId").asText();
  List<AzkabanJobExecRecord> results = parseJsonHelper(allJobs, flowExecId, flowPath);
  AzkabanJobExecUtil.sortAndSet(results);
  return results;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:19,代码来源:AzJobChecker.java

示例4: parse

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
 * For use in tests
 *
 * @param json incoming JSON to parse
 * @return a node tree
 * @throws IOException on any parsing problems
 */
public static ContainerNode parse(String json) throws IOException {
  ObjectMapper mapper = new ObjectMapper(factory);
  JsonNode jsonNode = mapper.readTree(json);
  if (!(jsonNode instanceof ContainerNode)) {
    throw new IOException("Wrong JSON data: " + json);
  }
  return (ContainerNode) jsonNode;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:16,代码来源:Log4Json.java

示例5: jsonTree

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public static JsonNode jsonTree(ObjectMapper m, String json) {
    try {
        JsonParser jp = factory.createJsonParser(new StringReader(json));
        m.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
        return m.readTree(jp);
    } catch (Exception e) {
        System.out.println(e);
    }
    return NULL_NODE;
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:11,代码来源:JsonUtil.java

示例6: testRMNMInfo

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testRMNMInfo() throws Exception {
  if (!(new File(MiniMRYarnCluster.APPJAR)).exists()) {
    LOG.info("MRAppJar " + MiniMRYarnCluster.APPJAR
         + " not found. Not running test.");
    return;
  }
  
  RMContext rmc = mrCluster.getResourceManager().getRMContext();
  ResourceScheduler rms = mrCluster.getResourceManager()
                                                 .getResourceScheduler();
  RMNMInfo rmInfo = new RMNMInfo(rmc,rms);
  String liveNMs = rmInfo.getLiveNodeManagers();
  ObjectMapper mapper = new ObjectMapper();
  JsonNode jn = mapper.readTree(liveNMs);
  Assert.assertEquals("Unexpected number of live nodes:",
                                             NUMNODEMANAGERS, jn.size());
  Iterator<JsonNode> it = jn.iterator();
  while (it.hasNext()) {
    JsonNode n = it.next();
    Assert.assertNotNull(n.get("HostName"));
    Assert.assertNotNull(n.get("Rack"));
    Assert.assertTrue("Node " + n.get("NodeId") + " should be RUNNING",
            n.get("State").asText().contains("RUNNING"));
    Assert.assertNotNull(n.get("NodeHTTPAddress"));
    Assert.assertNotNull(n.get("LastHealthUpdate"));
    Assert.assertNotNull(n.get("HealthReport"));
    Assert.assertNotNull(n.get("NodeManagerVersion"));
    Assert.assertNotNull(n.get("NumContainers"));
    Assert.assertEquals(
            n.get("NodeId") + ": Unexpected number of used containers",
            0, n.get("NumContainers").asInt());
    Assert.assertEquals(
            n.get("NodeId") + ": Unexpected amount of used memory",
            0, n.get("UsedMemoryMB").asInt());
    Assert.assertNotNull(n.get("AvailableMemoryMB"));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:39,代码来源:TestRMNMInfo.java

示例7: testRMNMInfoMissmatch

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Test
public void testRMNMInfoMissmatch() throws Exception {
  RMContext rmc = mock(RMContext.class);
  ResourceScheduler rms = mock(ResourceScheduler.class);
  ConcurrentMap<NodeId, RMNode> map = new ConcurrentHashMap<NodeId, RMNode>();
  RMNode node = MockNodes.newNodeInfo(1, MockNodes.newResource(4 * 1024));
  map.put(node.getNodeID(), node);
  when(rmc.getRMNodes()).thenReturn(map);
  
  RMNMInfo rmInfo = new RMNMInfo(rmc,rms);
  String liveNMs = rmInfo.getLiveNodeManagers();
  ObjectMapper mapper = new ObjectMapper();
  JsonNode jn = mapper.readTree(liveNMs);
  Assert.assertEquals("Unexpected number of live nodes:",
                                             1, jn.size());
  Iterator<JsonNode> it = jn.iterator();
  while (it.hasNext()) {
    JsonNode n = it.next();
    Assert.assertNotNull(n.get("HostName"));
    Assert.assertNotNull(n.get("Rack"));
    Assert.assertTrue("Node " + n.get("NodeId") + " should be RUNNING",
            n.get("State").asText().contains("RUNNING"));
    Assert.assertNotNull(n.get("NodeHTTPAddress"));
    Assert.assertNotNull(n.get("LastHealthUpdate"));
    Assert.assertNotNull(n.get("HealthReport"));
    Assert.assertNotNull(n.get("NodeManagerVersion"));
    Assert.assertNull(n.get("NumContainers"));
    Assert.assertNull(n.get("UsedMemoryMB"));
    Assert.assertNull(n.get("AvailableMemoryMB"));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:TestRMNMInfo.java

示例8: handleTextMessage

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
public ResponseGenerator handleTextMessage() throws Exception {
    ResponseGenerator responseGenerator = new ResponseGenerator();
    String[] rivescriptReply = helper.getRiveScriptBot().answer(request.getUserId(), textMessage);

    for(String reply : rivescriptReply) {
        if(Utility.isJSONObject(reply) == true) {
            ObjectMapper mapper = new ObjectMapper();
            JsonNode rootNode = mapper.readTree(reply);
            switch (rootNode.get("type").getTextValue()) {
                case RiveScriptReplyType.TEMPLATE_SCENARIO:
                    responseGenerator = new TemplateHandler(request, Utility.split(rootNode.get("name").getTextValue(), Utility.PARAMETER_SEPARATOR), helper)
                            .handleTemplateMessage();
                    break;
                case RiveScriptReplyType.LANGUAGE_SCENARIO:
                    responseGenerator = new LanguageHandler(request, rootNode.get("name").getTextValue(), helper)
                            .handleLanguageAbout();
                    break;
                case RiveScriptReplyType.STATUS_CHECK_SCENARIO:
                    responseGenerator = new StatusCheckHandler(request, rootNode.get("name").getTextValue(), helper).handleStatusCheck();
                    break;
                case RiveScriptReplyType.LOCATION_SCENARIO:
                    responseGenerator = new LocationHandler(request, rootNode.get("query").getTextValue(), helper).getLocation();
                    break;
                case RiveScriptReplyType.FALLBACK_SCENARIO:
                    // Eliza
                    if(textMessage.endsWith("!") || textMessage.endsWith(".")) {
                        responseGenerator.addTextResponse(new ResponseData(helper.getEliza().processInput(textMessage)));
                    }
                    else {
                        textMessage = rootNode.get("query").getTextValue(); // Use processed text message
                        responseGenerator = new NLHandler(request, textMessage, helper).answer();
                    }
                    break;
            }
        }
        else {
            responseGenerator.addTextResponse(new ResponseData(reply));
        }
    }

    // Fallback when everything else fails Eliza will answer
    if(responseGenerator.getResponse().size() == 0) {
        responseGenerator.addTextResponse(new ResponseData(helper.getEliza().processInput(textMessage)));
    }
    return responseGenerator;
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:47,代码来源:TextHandler.java

示例9: deserialize

import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
private EntityListing deserialize(final String serializedState) throws JsonParseException, JsonMappingException, IOException {
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode jsonNode = mapper.readTree(serializedState);
    return mapper.readValue(jsonNode, EntityListing.class);
}
 
开发者ID:clickha,项目名称:nifi-tools,代码行数:6,代码来源:AbstractListProcessor.java


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