List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.google.api.codegen.discovery.MainDiscoveryProviderFactory.java
public static DiscoveryProvider defaultCreate(Service service, ApiaryConfig apiaryConfig, JsonNode sampleConfigOverrides, String id) { // Use nodes corresponding to language pattern fields matching current language. List<JsonNode> overrides = new ArrayList<JsonNode>(); // Sort patterns to ensure deterministic ordering of overrides if (sampleConfigOverrides != null) { List<String> languagePatterns = Lists.newArrayList(sampleConfigOverrides.fieldNames()); Collections.sort(languagePatterns); for (String languagePattern : languagePatterns) { if (Pattern.matches(languagePattern, id)) { overrides.add(sampleConfigOverrides.get(languagePattern)); }/*from w w w . j a v a 2s . c o m*/ } } SampleMethodToViewTransformer sampleMethodToViewTransformer = null; TypeNameGenerator typeNameGenerator = null; try { sampleMethodToViewTransformer = SAMPLE_METHOD_TO_VIEW_TRANSFORMER_MAP.get(id).newInstance(); typeNameGenerator = TYPE_NAME_GENERATOR_MAP.get(id).newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } if (sampleMethodToViewTransformer == null || typeNameGenerator == null) { throw new NotImplementedException("MainDiscoveryProviderFactory: invalid id \"" + id + "\""); } return ViewModelProvider.newBuilder().setMethods(service.getApis(0).getMethodsList()) .setApiaryConfig(apiaryConfig) .setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())) .setMethodToViewTransformer(sampleMethodToViewTransformer).setOverrides(overrides) .setTypeNameGenerator(typeNameGenerator).setOutputRoot("autogenerated/" + apiaryConfig.getApiName() + "/" + apiaryConfig.getApiVersion() + "/" + service.getDocumentation().getOverview()) .build(); }
From source file:io.syndesis.dao.DeploymentDescriptorTest.java
private static void assertConnectorProperties(final String connectorId, final JsonNode connectorPropertiesJson, final JsonNode componentPropertiesFromCatalog) { // make sure that all connector properties are as defined in // the connector connectorPropertiesJson.fields().forEachRemaining(property -> { final String propertyName = property.getKey(); final JsonNode propertyDefinition = property.getValue(); final JsonNode catalogedPropertyDefinition = componentPropertiesFromCatalog.get(propertyName); assertThat(catalogedPropertyDefinition).as( "Definition of `%s` connector has a property `%s` that is not defined in the Camel connector", connectorId, propertyName).isNotNull(); assertThat(propertyDefinition.get("componentProperty")) .as("`componentProperty` field is missing for connector's %s property %s", connectorId, propertyName)//ww w. jav a 2s. co m .isNotNull(); assertThat(propertyDefinition.get("componentProperty").asBoolean()) .as("Definition of `%s` connector's property `%s` should be marked as `componentProperty`", connectorId, propertyName) .isTrue(); final ObjectNode propertyDefinitionForComparisson = propertyNodeForComparisson(propertyDefinition); // remove properties that we would like to customize removeCustomizedProperties(propertyDefinitionForComparisson, catalogedPropertyDefinition); assertThat(propertyDefinitionForComparisson) .as("Definition of `%s` connector's property `%s` differs from the one in Camel connector", connectorId, propertyName) .isEqualTo(catalogedPropertyDefinition); }); }
From source file:nl.esciencecenter.xnatclient.data.XnatParser.java
/** * Expect a single XnatObject at JsonNode * /*from ww w . j a va 2s. co m*/ * @return */ public static XnatObject parseXnatObject(XnatObjectType type, JsonNode node) { Iterator<String> names = node.fieldNames(); // create new object XnatObject obj = XnatObject.create(type); logger.debugPrintf(" - New XnatObject:<%s>\n", obj.getObjectType()); // use headers from XnatObject definition (not json): StringList headerList = new StringList(obj.getFieldNames()); for (int i = 0; i < headerList.size(); i++) { String name = headerList.get(i); JsonNode fieldObj = node.get(name); if (fieldObj != null) { String text = fieldObj.asText(); logger.debugPrintf(" - - set %s='%s'\n", name, text); obj.set(name, text); } } return obj; }
From source file:com.dnw.json.J.java
/** * Resolves an object <code>JsonNode</code>, returns a <code>com.dnw.json.M</code> object. For * each value of key-value pair, recursively calls <code>parse(JsonNode)</code> to resolve it. * //from w w w. ja va 2 s. c o m * @author manbaum * @since Oct 22, 2014 * @param node the given <code>JsonNode</code>. * @return a <code>com.dnw.json.M</code> object. */ private final static M resolveObject(JsonNode node) { M m = M.m(); Iterator<String> i = node.fieldNames(); while (i.hasNext()) { String key = i.next(); m.a(key, resolve(node.get(key))); } return m; }
From source file:nextflow.fs.dx.DxFileSystemProvider.java
/** * Find out the default DnaNexus project id in the specified configuration file * * @return The string value/*www. j av a 2 s. com*/ */ static String getContextIdByConfig(File config) { StringBuilder buffer = new StringBuilder(); try { BufferedReader reader = Files.newBufferedReader(config.toPath(), Charset.defaultCharset()); String line; while ((line = reader.readLine()) != null) { buffer.append(line).append('\n'); } JsonNode object = DxJson.parseJson(buffer.toString()); return object.get("DX_PROJECT_CONTEXT_ID").textValue(); } catch (FileNotFoundException e) { throw new IllegalStateException(String.format( "Unable to load DnaNexus configuration file: %s -- cannot configure file system", config), e); } catch (IOException e) { throw new IllegalStateException("Unable to configure DnaNexus file system", e); } }
From source file:com.flipkart.zjsonpatch.JsonDiff.java
private static void compareArray(List<Diff> diffs, List<Object> path, JsonNode source, JsonNode target) { List<JsonNode> lcs = getLCS(source, target); int srcIdx = 0; int targetIdx = 0; int lcsIdx = 0; int srcSize = source.size(); int targetSize = target.size(); int lcsSize = lcs.size(); int pos = 0;/*from ww w.j a v a 2s .c o m*/ while (lcsIdx < lcsSize) { JsonNode lcsNode = lcs.get(lcsIdx); JsonNode srcNode = source.get(srcIdx); JsonNode targetNode = target.get(targetIdx); if (lcsNode.equals(srcNode) && lcsNode.equals(targetNode)) { // Both are same as lcs node, nothing to do here srcIdx++; targetIdx++; lcsIdx++; pos++; } else { if (lcsNode.equals(srcNode)) { // src node is same as lcs, but not targetNode //addition List<Object> currPath = getPath(path, pos); diffs.add(Diff.generateDiff(Operation.ADD, currPath, targetNode)); pos++; targetIdx++; } else if (lcsNode.equals(targetNode)) { //targetNode node is same as lcs, but not src //removal, List<Object> currPath = getPath(path, pos); diffs.add(Diff.generateDiff(Operation.REMOVE, currPath, srcNode)); srcIdx++; } else { List<Object> currPath = getPath(path, pos); //both are unequal to lcs node generateDiffs(diffs, currPath, srcNode, targetNode); srcIdx++; targetIdx++; pos++; } } } while ((srcIdx < srcSize) && (targetIdx < targetSize)) { JsonNode srcNode = source.get(srcIdx); JsonNode targetNode = target.get(targetIdx); List<Object> currPath = getPath(path, pos); generateDiffs(diffs, currPath, srcNode, targetNode); srcIdx++; targetIdx++; pos++; } pos = addRemaining(diffs, path, target, pos, targetIdx, targetSize); removeRemaining(diffs, path, pos, srcIdx, srcSize, source); }
From source file:net.bcsw.sdnwlan.config.AccessPointConfig.java
public static AccessPointConfig valueOf(JsonNode accessNode) throws ConfigException { try {//from w ww . j a va2 s. c om // First some required values MacAddress macAddress = MacAddress.valueOf(accessNode.path(MAC_ADDRESS).asText()); if (macAddress == null || macAddress.equals(MacAddress.ZERO)) { // TODO: Could stand a few more checks here... throw new IllegalArgumentException("Invalid MAC Address"); } List<ConnectPoint> connections = Lists.newArrayList(); JsonNode gateways = accessNode.get(CONNECTIONS); if (gateways != null) { gateways.forEach(jsonNode -> connections.add(ConnectPoint.deviceConnectPoint(jsonNode.asText()))); } if (connections.size() == 0) { throw new IllegalArgumentException("Invalid/missing access point connnection"); } List<GatewayConfig> defaultGateways = Lists.newArrayList(); if (accessNode.has(GatewayConfig.GATEWAY_CONFIG)) { ArrayNode gwConfigArray = (ArrayNode) accessNode.get(GatewayConfig.GATEWAY_CONFIG); gwConfigArray.forEach(gwNode -> { try { defaultGateways.add(GatewayConfig.valueOf(gwNode)); } catch (ConfigException e) { throw new IllegalArgumentException("Error parsing gateway configs", e); } }); } if (defaultGateways.size() == 0) { throw new IllegalArgumentException("Invalid/missing default gateways"); } /////////////////////////////////////////////////////////////////////// // Now other minor or optional values // TODO: Some additional error checking would be good idea here String name = accessNode.path(NAME).asText("").trim(); double longitude = accessNode.path(LONGITUDE).asDouble(0.0); double latitude = accessNode.path(LATITUDE).asDouble(0.0); double altitude = accessNode.path(ALTITUDE).asDouble(0.0); Map<IpGatewayAndMask, List<VlanId>> otherGateways = Maps.newHashMap(); if (accessNode.has(OTHER_VIDS)) { ArrayNode vidNodeArray = (ArrayNode) accessNode.path(OTHER_VIDS); try { vidNodeArray.forEach(vidNode -> { String dummy = "OtherVid entry: " + vidNode.toString(); IpGatewayAndMask gateway = IpGatewayAndMask .valueOf(vidNode.get(OTHER_VIDS_GATEWAY).asText()); List<VlanId> otherVlans = Lists.newArrayList(); JsonNode otherVids = vidNode.get(OTHER_VIDS_VLANS); if (otherVids != null) { otherVids.forEach(jsonNode -> otherVlans.add(VlanId.vlanId((short) jsonNode.asInt()))); } if (otherGateways.put(gateway, otherVlans) != null) { throw new IllegalArgumentException( "Duplicate gateway in othervid list: " + gateway.toString()); } }); } catch (IllegalArgumentException e) { throw new ConfigException("Error parsing compute node connections", e); } } IngressVlans ingressVlans = new IngressVlans(); if (accessNode.has(IngressVlans.INGRESS_VLANS)) { ingressVlans = new IngressVlans((ArrayNode) accessNode.path(IngressVlans.INGRESS_VLANS)); } return new AccessPointConfig(name, macAddress, ingressVlans, defaultGateways, longitude, latitude, altitude, otherGateways, connections); } catch (IllegalArgumentException e) { throw new ConfigException("Error parsing compute node connections", e); } }
From source file:controllers.user.UserSettingApp.java
/** * ????//from w w w . j av a 2 s . c om * * @return */ public static Result phoneNumExists() { JsonNode json = getJson(); // ? boolean isValidParams = json.hasNonNull("phoneNum"); if (!isValidParams) { return illegalParameters(); } ObjectNodeResult result = new ObjectNodeResult(); String phoneNum = json.get("phoneNum").asText(); if (HelomeUtil.trim(phoneNum).length() != 11) { result.error("?"); } else { PhoneNumExistResult validateResult = UserCenterService.validatePhoneNumExist(phoneNum); if (PhoneNumExistResult.EXIST == validateResult) { result.put("exists", true); } else if (PhoneNumExistResult.NOT_EXIST == validateResult) { result.put("exists", false); } else { result.error(""); } } return ok(result.getObjectNode()); }
From source file:org.hawkular.alerts.api.json.JacksonDeserializer.java
public static Map<String, String> deserializeMap(JsonNode mapNode) { Map<String, String> map = new HashMap<>(); Iterator<String> fieldNames = mapNode.fieldNames(); while (fieldNames.hasNext()) { String field = fieldNames.next(); map.put(field, mapNode.get(field).asText()); }//from w w w . j a va 2s . c om return map; }
From source file:com.meetingninja.csse.database.UserDatabaseAdapter.java
public static Schedule parseSchedule(JsonNode node) { // Initialize ObjectMapper Schedule sched = null;//from ww w . j a v a 2 s . co m Event event = null; // task or meeting final JsonNode scheduleArray = node.get(Keys.User.SCHEDULE); JsonNode _id; if (scheduleArray.isArray()) { sched = new Schedule(); // start parsing a schedule for (final JsonNode meetingOrTaskNode : scheduleArray) { if ((_id = meetingOrTaskNode.get(Keys._ID)) != null) { // Get the type of event String type = JsonUtils.getJSONValue(meetingOrTaskNode, Keys.TYPE); if (TextUtils.equals(type, "meeting")) { event = new Meeting(); } else if (TextUtils.equals(type, "task")) { event = new Task(); } if (event != null) { event.setID(_id.asText()); event.setTitle(JsonUtils.getJSONValue(meetingOrTaskNode, Keys.Meeting.TITLE)); event.setDescription(JsonUtils.getJSONValue(meetingOrTaskNode, Keys.Meeting.DESC)); event.setStartTime(JsonUtils.getJSONValue(meetingOrTaskNode, Keys.Meeting.START)); event.setEndTime(JsonUtils.getJSONValue(meetingOrTaskNode, Keys.Meeting.END)); // Add event to the schedule if (event instanceof Meeting) sched.addMeeting((Meeting) event); else if (event instanceof Task) sched.addTask((Task) event); else Log.w(TAG + "> getSchedule", "Event cast failure"); } } } // end for } return sched; }