Java Code Examples for com.fasterxml.jackson.databind.node.JsonNodeType#STRING
The following examples show how to use
com.fasterxml.jackson.databind.node.JsonNodeType#STRING .
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: GenerateBlockchainConfig.java From besu with Apache License 2.0 | 6 votes |
/** * Imports a single public key. * * @param publicKeyJson The public key. */ private void importPublicKey(final JsonNode publicKeyJson) { if (publicKeyJson.getNodeType() != JsonNodeType.STRING) { throw new IllegalArgumentException( "Invalid key json of type: " + publicKeyJson.getNodeType()); } final String publicKeyText = publicKeyJson.asText(); try { final SECP256K1.PublicKey publicKey = SECP256K1.PublicKey.create(Bytes.fromHexString(publicKeyText)); writeKeypair(publicKey, null); LOG.info("Public key imported from configuration.({})", publicKey.toString()); } catch (final IOException e) { LOG.error("An error occurred while trying to import node public key.", e); } }
Example 2
Source File: JsonCacheImpl.java From openapi-generator with Apache License 2.0 | 6 votes |
protected JsonNodeType nodeTypeFor(Object value) { JsonNodeType type; if (value == null) { type = JsonNodeType.NULL; } else if (value instanceof Boolean) { type = JsonNodeType.BOOLEAN; } else if (value instanceof Number) { type = JsonNodeType.NUMBER; } else if (value instanceof String) { type = JsonNodeType.STRING; } else if (value instanceof ArrayNode || value instanceof List) { type = JsonNodeType.ARRAY; } else if (value instanceof byte[]) { type = JsonNodeType.BINARY; } else if (value instanceof ObjectNode || value instanceof Map) { type = JsonNodeType.OBJECT; } else { type = JsonNodeType.POJO; } return type; }
Example 3
Source File: JobClient.java From genie with Apache License 2.0 | 6 votes |
/** * Method to fetch the status of a job. * * @param jobId The id of the job. * @return The status of the Job. * @throws GenieClientException If the response recieved is not 2xx. * @throws IOException For Network and other IO issues. */ public JobStatus getJobStatus( final String jobId ) throws IOException, GenieClientException { if (StringUtils.isEmpty(jobId)) { throw new IllegalArgumentException("Missing required parameter: jobId."); } final JsonNode jsonNode = this.jobService.getJobStatus(jobId).execute().body(); if (jsonNode == null || jsonNode.getNodeType() != JsonNodeType.OBJECT) { throw new GenieClientException("Unknown response from server: " + jsonNode); } try { final JsonNode statusNode = jsonNode.get(STATUS); if (statusNode == null || statusNode.getNodeType() != JsonNodeType.STRING) { throw new GenieClientException("Unknown response format for status: " + statusNode); } return JobStatus.parse(statusNode.asText()); } catch (GeniePreconditionException ge) { throw new GenieClientException(ge.getMessage()); } }
Example 4
Source File: FeedMessageDeserializer.java From incubator-tuweni with Apache License 2.0 | 5 votes |
private Optional<String> getType(JsonNode content) { if (content.getNodeType() != JsonNodeType.STRING) { JsonNode type = content.get("type"); return Optional.of(type.asText()); } else { return Optional.empty(); } }
Example 5
Source File: LoginEncryptionUtils.java From Geyser with MIT License | 5 votes |
private static void encryptConnectionWithCert(GeyserConnector connector, GeyserSession session, String clientData, JsonNode certChainData) { try { boolean validChain = validateChainData(certChainData); connector.getLogger().debug(String.format("Is player data valid? %s", validChain)); JWSObject jwt = JWSObject.parse(certChainData.get(certChainData.size() - 1).asText()); JsonNode payload = JSON_MAPPER.readTree(jwt.getPayload().toBytes()); if (payload.get("extraData").getNodeType() != JsonNodeType.OBJECT) { throw new RuntimeException("AuthData was not found!"); } JsonNode extraData = payload.get("extraData"); session.setAuthenticationData(new AuthData( extraData.get("displayName").asText(), UUID.fromString(extraData.get("identity").asText()), extraData.get("XUID").asText() )); if (payload.get("identityPublicKey").getNodeType() != JsonNodeType.STRING) { throw new RuntimeException("Identity Public Key was not found!"); } ECPublicKey identityPublicKey = EncryptionUtils.generateKey(payload.get("identityPublicKey").textValue()); JWSObject clientJwt = JWSObject.parse(clientData); EncryptionUtils.verifyJwt(clientJwt, identityPublicKey); session.setClientData(JSON_MAPPER.convertValue(JSON_MAPPER.readTree(clientJwt.getPayload().toBytes()), BedrockClientData.class)); if (EncryptionUtils.canUseEncryption()) { LoginEncryptionUtils.startEncryptionHandshake(session, identityPublicKey); } } catch (Exception ex) { session.disconnect("disconnectionScreen.internalError.cantConnect"); throw new RuntimeException("Unable to complete login", ex); } }
Example 6
Source File: JSONExamples.java From Java-for-Data-Science with MIT License | 5 votes |
public void treeTraversalSolution() { try { ObjectMapper mapper = new ObjectMapper(); // use the ObjectMapper to read the json string and create a tree JsonNode node = mapper.readTree(new File("Persons.json")); Iterator<String> fieldNames = node.fieldNames(); while (fieldNames.hasNext()) { JsonNode personsNode = node.get("persons"); Iterator<JsonNode> elements = personsNode.iterator(); while (elements.hasNext()) { JsonNode element = elements.next(); JsonNodeType nodeType = element.getNodeType(); if (nodeType == JsonNodeType.STRING) { out.println("Group: " + element.textValue()); } if (nodeType == JsonNodeType.ARRAY) { Iterator<JsonNode> fields = element.iterator(); while (fields.hasNext()) { parsePerson(fields.next()); } } } fieldNames.next(); } } catch (IOException ex) { ex.printStackTrace(); } }
Example 7
Source File: RoutingConfigParser.java From styx with Apache License 2.0 | 5 votes |
public static StyxObjectConfiguration toRoutingConfigNode(JsonNode jsonNode) { if (jsonNode.getNodeType() == JsonNodeType.STRING) { return new StyxObjectReference(jsonNode.asText()); } else if (jsonNode.getNodeType() == JsonNodeType.OBJECT) { String name = getOrElse(jsonNode, "name", ""); String type = getMandatory(jsonNode, "type", format("Routing config definition must have a 'type' attribute in def='%s'", name)); JsonNode conf = jsonNode.get("config"); return new StyxObjectDefinition(name, type, conf); } throw new IllegalArgumentException("invalid configuration"); }
Example 8
Source File: CustomAttributeDeserializer.java From intercom-java with Apache License 2.0 | 5 votes |
@Override public CustomAttribute deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { CustomAttribute cda = null; final String currentName = jp.getParsingContext().getCurrentName(); final ObjectMapper mapper = (ObjectMapper) jp.getCodec(); final ValueNode vNode = mapper.readTree(jp); if (vNode.asToken().isScalarValue()) { if (vNode.getNodeType() == JsonNodeType.BOOLEAN) { cda = new CustomAttribute<Boolean>(currentName, vNode.asBoolean(), Boolean.class); } else if (vNode.getNodeType() == JsonNodeType.STRING) { cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class); } else if (vNode.getNodeType() == JsonNodeType.NUMBER) { final NumericNode nNode = (NumericNode) vNode; if (currentName.endsWith("_at")) { cda = new CustomAttribute<Long>(currentName, vNode.longValue(), Long.class); } else if (nNode.isInt()) { cda = new CustomAttribute<Integer>(currentName, vNode.intValue(), Integer.class); } else if (nNode.isFloat()) { cda = new CustomAttribute<Float>(currentName, vNode.floatValue(), Float.class); } else if (nNode.isDouble()) { cda = new CustomAttribute<Double>(currentName, vNode.doubleValue(), Double.class); } else if (nNode.isLong()) { cda = new CustomAttribute<Long>(currentName, vNode.longValue(), Long.class); } else { cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class); } } else { cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class); } } return cda; }
Example 9
Source File: StringMatch.java From link-move with Apache License 2.0 | 5 votes |
@Override protected boolean apply(JsonNode lhsValue, JsonNode rhsValue) { if (lhsValue.getNodeType() != JsonNodeType.STRING) { return false; } // assume that regex is always on the right-hand side of this op Pattern pattern = Pattern.compile(rhsValue.asText()); if (rhsValue.getNodeType() != JsonNodeType.STRING) { throw new RuntimeException("Not a regular expression: " + rhsValue.asText()); } return pattern.matcher(lhsValue.asText()).matches(); }
Example 10
Source File: JsonDataModelTree.java From onos with Apache License 2.0 | 5 votes |
/** * Creating empty json node. * * @param type json node type to create * @return created json node * @throws WorkflowException workflow exception */ private JsonNode createEmpty(JsonNodeType type) throws WorkflowException { if (type == JsonNodeType.OBJECT) { return JsonNodeFactory.instance.objectNode(); } else if (type == JsonNodeType.ARRAY) { return JsonNodeFactory.instance.arrayNode(); } else if (type == JsonNodeType.STRING) { return JsonNodeFactory.instance.textNode(""); } else { throw new WorkflowException("Not supported JsonNodetype(" + type + ")"); } }
Example 11
Source File: JsonQueryObjectModelConverter.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
private void parseProperties(QueryPart queryPart, ObjectNode properties) throws QueryException { Iterator<Entry<String, JsonNode>> fields = properties.fields(); while (fields.hasNext()) { Entry<String, JsonNode> entry = fields.next(); String propertySetName = entry.getKey(); JsonNode value = entry.getValue(); if (value.isObject()) { ObjectNode set = (ObjectNode)value; Iterator<Entry<String, JsonNode>> propertySetFields = set.fields(); while (propertySetFields.hasNext()) { Entry<String, JsonNode> propertyEntry = propertySetFields.next(); JsonNode propertyValue = propertyEntry.getValue(); if (propertyValue.isValueNode()) { if (propertyValue.getNodeType() == JsonNodeType.BOOLEAN) { queryPart.addProperty(propertySetName, propertyEntry.getKey(), propertyValue.asBoolean()); } else if (propertyValue.getNodeType() == JsonNodeType.NUMBER) { queryPart.addProperty(propertySetName, propertyEntry.getKey(), propertyValue.asDouble()); } else if (propertyValue.getNodeType() == JsonNodeType.STRING) { queryPart.addProperty(propertySetName, propertyEntry.getKey(), propertyValue.asText()); } else if (propertyValue.getNodeType() == JsonNodeType.NULL) { queryPart.addProperty(propertySetName, propertyEntry.getKey(), null); } } else { throw new QueryException("property \"" + propertyEntry.getKey() + "\" type not supported"); } } } else { throw new QueryException("Query language has changed, propertyset name required now"); } } }
Example 12
Source File: Jackson.java From centraldogma with Apache License 2.0 | 4 votes |
public static String textValue(JsonNode node, String defaultValue) { return node != null && node.getNodeType() == JsonNodeType.STRING ? node.textValue() : defaultValue; }
Example 13
Source File: IsJsonText.java From java-hamcrest with Apache License 2.0 | 4 votes |
private IsJsonText(final Matcher<? super String> textMatcher) { super(JsonNodeType.STRING); this.textMatcher = Objects.requireNonNull(textMatcher); }
Example 14
Source File: CodeTransProcessor.java From vertx-codetrans with Apache License 2.0 | 4 votes |
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); String outputOption = processingEnv.getOptions().get("codetrans.output"); if (outputOption != null) { outputDir = new File(outputOption); } translator = new CodeTranslator(processingEnv); langs = new ArrayList<>(); String renderOpt = processingEnv.getOptions().get("codetrans.render"); renderMode = renderOpt != null ? RenderMode.valueOf(renderOpt.toUpperCase()) : RenderMode.EXAMPLE; String langsOpt = processingEnv.getOptions().get("codetrans.langs"); Set<String> langs; if (langsOpt != null) { langs = new HashSet<>(Arrays.asList(langsOpt.split("\\s*,\\s*"))); } else { langs = new HashSet<>(Arrays.asList("js", "ruby", "kotlin", "groovy")); } String configOpt = processingEnv.getOptions().get("codetrans.config"); if (configOpt != null) { ObjectMapper mapper = new ObjectMapper() .enable(JsonParser.Feature.ALLOW_COMMENTS) .enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); File file = new File(configOpt); try { config = (ObjectNode) mapper.readTree(file); } catch (IOException e) { System.err.println("[ERROR] Cannot read configuration file " + file.getAbsolutePath() + " : " + e.getMessage()); e.printStackTrace(); } } for (String lang : langs) { Lang l; switch (lang) { case "kotlin": l = new KotlinLang(); break; case "groovy": l = new GroovyLang(); break; case "scala": l = new ScalaLang(); break; default: continue; } this.langs.add(l); if (config != null) { JsonNode n = config.get(lang); if (n != null && n.getNodeType() == JsonNodeType.OBJECT) { JsonNode excludes = n.get("excludes"); if (excludes != null && excludes.getNodeType() == JsonNodeType.ARRAY) { Set<String> t = new HashSet<>(); abc.put(l.id(), t); for (int i = 0;i < excludes.size();i++) { JsonNode c = excludes.get(i); if (c.getNodeType() == JsonNodeType.STRING) { TextNode tn = (TextNode) c; t.add(tn.asText()); } } } } } } }
Example 15
Source File: JsonNode.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Method that checks whether this node represents basic JSON String * value. */ public final boolean isTextual() { return getNodeType() == JsonNodeType.STRING; }