Java Code Examples for com.fasterxml.jackson.databind.JsonNode#findPath()
The following examples show how to use
com.fasterxml.jackson.databind.JsonNode#findPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AristaUtils.java From onos with Apache License 2.0 | 6 votes |
public static boolean getWithChecking(DriverHandler handler, List<String> commands) { RestSBController controller = checkNotNull(handler.get(RestSBController.class)); DeviceId deviceId = checkNotNull(handler.data()).deviceId(); String response = generate(commands); log.debug("request :{}", response); try { ObjectMapper om = new ObjectMapper(); JsonNode json = om.readTree(response); JsonNode errNode = json.findPath(ERROR); if (errNode.isMissingNode()) { return true; } log.error("Error get with checking {}", errNode.asText("")); for (String str : commands) { log.error("Command Failed due to Cmd : {}", str); } return false; } catch (IOException e) { log.error("IO exception occured because of ", e); return false; } }
Example 2
Source File: YoutubeChannelDeserializer.java From streams with Apache License 2.0 | 6 votes |
@Override public Channel deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); try { Channel channel = new Channel(); if (node.findPath("etag") != null) { channel.setEtag(node.get("etag").asText()); } if (node.findPath("kind") != null) { channel.setKind(node.get("kind").asText()); } channel.setId(node.get("id").asText()); channel.setTopicDetails(setTopicDetails(node.findValue("topicDetails"))); channel.setStatistics(setChannelStatistics(node.findValue("statistics"))); channel.setContentDetails(setContentDetails(node.findValue("contentDetails"))); channel.setSnippet(setChannelSnippet(node.findValue("snippet"))); return channel; } catch (Throwable throwable) { throw new IOException(throwable); } }
Example 3
Source File: GitLabRepoModel.java From gitpitch with MIT License | 5 votes |
private GitLabRepoModel(PitchParams pp, JsonNode json) { this._pp = pp; if(pp != null) { this._pretty = new StringBuffer(SLASH) .append(this._pp.user) .append(SLASH) .append(this._pp.repo) .toString(); this._cacheKey = genKey(pp); } /* * Generate derived data on instance only if the GitLab * API JSON is available for processing. */ if (json != null) { this._type = USER_TYPE; this._desc = json.findPath(DESCRIPTION).textValue(); this._lang = null; JsonNode namespaceNode = json.findPath(NAMESPACE); if(namespaceNode != null) { this._created = namespaceNode.findPath(CREATED_AT).textValue(); this._updated = namespaceNode.findPath(UPDATED_AT).textValue(); } this._stars = json.findPath(STAR_COUNT).asInt(); this._forks = json.findPath(FORKS_COUNT).asInt(); this._issues = json.findPath(OPEN_ISSUES_COUNT).asInt(); this._hasWiki = json.findPath(WIKI_ENABLED).asBoolean(); this._hasPages = false; this._private = json.findPath(VISIBILITY).textValue() != PUBLIC; } }
Example 4
Source File: DndTeamInfoTest.java From slack-api with MIT License | 5 votes |
@Test public void deserializeTest() throws JsonProcessingException, IOException { StringBuffer json = new StringBuffer(); json.append(" { "); json.append(" \"ok\": true, "); json.append(" \"users\": { "); json.append(" \"U07GVSQ2Z\": { "); json.append(" \"dnd_enabled\": true, "); json.append(" \"next_dnd_start_ts\": 1455195600, "); json.append(" \"next_dnd_end_ts\": 1455231600 "); json.append(" }, "); json.append(" \"U08AHNL0H\": { "); json.append(" \"dnd_enabled\": true, "); json.append(" \"next_dnd_start_ts\": 1455195600, "); json.append(" \"next_dnd_end_ts\": 1455231600 "); json.append(" } "); json.append(" } "); json.append(" } "); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(json.toString()); jsonNode = jsonNode.findPath("users"); Map<String, DndSimpleInfo> maps = objectMapper.readValue(jsonNode.toString(), new TypeReference<Map<String, DndSimpleInfo>>() { }); for (Entry<String, DndSimpleInfo> entry : maps.entrySet()) { System.out.println(entry.getKey()); DndSimpleInfo dndSimpleInfo = entry.getValue(); System.out.print("dnd_enabled : " + dndSimpleInfo.getDnd_enabled()); System.out.print(" next_dnd_start_ts : " + dndSimpleInfo.getNext_dnd_start_ts()); System.out.println(" next_dnd_end_ts : " + dndSimpleInfo.getNext_dnd_end_ts()); } }
Example 5
Source File: SlackWebApiClientImpl.java From slack-api with MIT License | 5 votes |
protected <T> T readValue(JsonNode node, String findPath, TypeReference<?> typeReference) { try { if (findPath != null) { if (!node.has(findPath)) return null; node = node.findPath(findPath); } return mapper.readValue(node.toString(), typeReference); } catch (IOException e) { throw new RuntimeException(e); } }
Example 6
Source File: SlackWebApiClientImpl.java From slack-api with MIT License | 5 votes |
protected <T> T readValue(JsonNode node, String findPath, Class<T> valueType) { try { if (findPath != null) { if (!node.has(findPath)) return null; node = node.findPath(findPath); } return mapper.readValue(node.toString(), valueType); } catch (IOException e) { throw new RuntimeException(e); } }
Example 7
Source File: BitBucketRepoModel.java From gitpitch with MIT License | 5 votes |
private BitBucketRepoModel(PitchParams pp, JsonNode json) { this._pp = pp; if(pp != null) { this._pretty = new StringBuffer(SLASH) .append(this._pp.user) .append(SLASH) .append(this._pp.repo) .toString(); this._cacheKey = genKey(pp); } /* * Generate derived data on instance only if the BitBucket * API JSON is available for processing. */ if (json != null) { JsonNode ownerNode = json.findPath(OWNER); this._type = ownerNode.findPath(TYPE).textValue(); this._desc = json.findPath(DESCRIPTION).textValue(); this._created = json.findPath(CREATED_ON).textValue(); this._updated = json.findPath(UPDATED_ON).textValue(); this._lang = json.findPath(LANGUAGE).textValue(); this._stars = 0; this._forks = 0; this._issues = 0; this._hasWiki = json.findPath(HAS_WIKI).asBoolean(); this._hasPages = false; this._private = json.findPath(IS_PRIVATE).asBoolean(); } }
Example 8
Source File: GitHubRepoModel.java From gitpitch with MIT License | 5 votes |
private GitHubRepoModel(PitchParams pp, JsonNode json) { this._pp = pp; if(pp != null) { this._pretty = new StringBuffer(SLASH) .append(this._pp.user) .append(SLASH) .append(this._pp.repo) .toString(); this._cacheKey = genKey(pp); } /* * Generate derived data on instance only if the GitHub * API JSON is available for processing. */ if (json != null) { JsonNode ownerNode = json.findPath(OWNER); this._type = ownerNode.findPath(TYPE).textValue(); this._desc = json.findPath(DESCRIPTION).textValue(); this._created = json.findPath(CREATED_AT).textValue(); this._updated = json.findPath(UPDATED_AT).textValue(); this._lang = json.findPath(LANGUAGE).textValue(); this._stars = json.findPath(STARGAZERS_COUNT).asInt(); this._forks = json.findPath(FORKS_COUNT).asInt(); this._issues = json.findPath(OPEN_ISSUES).asInt(); this._hasWiki = json.findPath(HAS_WIKI).asBoolean(); this._hasPages = json.findPath(HAS_PAGES).asBoolean(); this._private = json.findPath(PRIVATE).asBoolean(); } }
Example 9
Source File: SlackClientServiceImpl.java From c4sg-services with MIT License | 5 votes |
protected <T> T readValue(JsonNode node, String findPath, TypeReference<?> typeReference) { try { if (findPath != null) { if (!node.has(findPath)) return null; node = node.findPath(findPath); } return mapper.readValue(node.toString(), typeReference); } catch (IOException e) { throw new RuntimeException(e); } }
Example 10
Source File: SlackClientServiceImpl.java From c4sg-services with MIT License | 5 votes |
protected <T> T readValue(JsonNode node, String findPath, Class<T> valueType) { try { if (findPath != null) { if (!node.has(findPath)) return null; node = node.findPath(findPath); } return mapper.readValue(node.toString(), valueType); } catch (IOException e) { throw new RuntimeException(e); } }
Example 11
Source File: GoGradleLockParser.java From synopsys-detect with Apache License 2.0 | 5 votes |
public DependencyGraph parse(final File goGradleLockFile) throws IOException, IntegrationException { final MutableDependencyGraph dependencyGraph = new MutableMapDependencyGraph(); final YAMLMapper mapper = new YAMLMapper(); final JsonNode rootNode = mapper.readTree(goGradleLockFile); final JsonNode buildNode = rootNode.findPath("build"); if (buildNode == null) { throw new IntegrationException(String.format("Failed to find build node in %s", GoGradleDetectable.GO_GRADLE_LOCK)); } for (final JsonNode dependencyNode : buildNode) { final Optional<String> name = Optional.ofNullable(dependencyNode.get("name")).map(JsonNode::textValue); final Optional<String> commit = Optional.ofNullable(dependencyNode.get("commit")).map(JsonNode::textValue); if (name.isPresent() && commit.isPresent()) { String dependencyName = name.get(); if (dependencyName.startsWith("golang.org/x/")) { dependencyName = dependencyName.replace("golang.org/x/", ""); } final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.GOLANG, dependencyName, commit.get()); final Dependency dependency = new Dependency(externalId); dependencyGraph.addChildToRoot(dependency); } } return dependencyGraph; }
Example 12
Source File: GiteaRepoModel.java From gitpitch with MIT License | 4 votes |
private GiteaRepoModel(PitchParams pp, JsonNode json) { this._pp = pp; this._pretty = new StringBuffer(SLASH) .append(this._pp.user) .append(SLASH) .append(this._pp.repo) .toString(); this._cacheKey = genKey(pp); /* * Generate derived data on instance only if the GitHub * API JSON is available for processing. */ if (json != null) { JsonNode ownerNode = json.findPath("owner"); this._type = null; this._desc = json.findPath("description").textValue(); this._created = json.findPath("created_at").textValue(); this._updated = json.findPath("updated_at").textValue(); this._lang = null; this._stars = json.findPath("stars_count").asInt(); this._forks = json.findPath("forks_count").asInt(); this._issues = json.findPath("open_issues.count").asInt(); this._hasWiki = false; this._hasPages = false; } else { this._type = null; this._desc = null; this._created = null; this._updated = null; this._lang = null; this._stars = 0; this._forks = 0; this._issues = 0; this._hasWiki = false; this._hasPages = false; } }
Example 13
Source File: GogsRepoModel.java From gitpitch with MIT License | 4 votes |
private GogsRepoModel(PitchParams pp, JsonNode json) { this._pp = pp; this._pretty = new StringBuffer(SLASH) .append(this._pp.user) .append(SLASH) .append(this._pp.repo) .toString(); this._cacheKey = genKey(pp); /* * Generate derived data on instance only if the GitHub * API JSON is available for processing. */ if (json != null) { JsonNode ownerNode = json.findPath("owner"); this._type = null; this._desc = json.findPath("description").textValue(); this._created = json.findPath("created_at").textValue(); this._updated = json.findPath("updated_at").textValue(); this._lang = null; this._stars = json.findPath("stars_count").asInt(); this._forks = json.findPath("forks_count").asInt(); this._issues = json.findPath("open_issues.count").asInt(); this._hasWiki = false; this._hasPages = false; } else { this._type = null; this._desc = null; this._created = null; this._updated = null; this._lang = null; this._stars = 0; this._forks = 0; this._issues = 0; this._hasWiki = false; this._hasPages = false; } }
Example 14
Source File: SchemaTransformer.java From aws-apigateway-importer with Apache License 2.0 | 4 votes |
private JsonNode getSchema(String schemaName, JsonNode models) { return models.findPath(schemaName); }
Example 15
Source File: JiraAdapter.java From ods-provisioning-app with Apache License 2.0 | 4 votes |
public static BiPredicate<String, String> createFindPathAndCompare(JsonNode json) { return (path, value) -> { JsonNode key = json.findPath(path); return key != null && key.asText().equalsIgnoreCase(value); }; }
Example 16
Source File: MapperUtils.java From MyShopPlus with Apache License 2.0 | 2 votes |
/** * 将指定节点的 JSON 数据转换为 JavaBean * * @param jsonString * @param clazz * @return * @throws Exception */ public static <T> T json2pojoByTree(String jsonString, String treeNode, Class<T> clazz) throws Exception { JsonNode jsonNode = objectMapper.readTree(jsonString); JsonNode data = jsonNode.findPath(treeNode); return json2pojo(data.toString(), clazz); }
Example 17
Source File: MapperUtils.java From MyShopPlus with Apache License 2.0 | 2 votes |
/** * 将指定节点的 JSON 数组转换为集合 * * @param jsonStr JSON 字符串 * @param treeNode 查找 JSON 中的节点 * @return * @throws Exception */ public static <T> List<T> json2listByTree(String jsonStr, String treeNode, Class<T> clazz) throws Exception { JsonNode jsonNode = objectMapper.readTree(jsonStr); JsonNode data = jsonNode.findPath(treeNode); return json2list(data.toString(), clazz); }