當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonNodeType.STRING屬性代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.node.JsonNodeType.STRING屬性的典型用法代碼示例。如果您正苦於以下問題:Java JsonNodeType.STRING屬性的具體用法?Java JsonNodeType.STRING怎麽用?Java JsonNodeType.STRING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.fasterxml.jackson.databind.node.JsonNodeType的用法示例。


在下文中一共展示了JsonNodeType.STRING屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: treeTraversalSolution

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();
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-for-Data-Science,代碼行數:30,代碼來源:JSONExamples.java

示例2: getUri

public URI getUri(int index) {
	JsonNode uris = getMetadata().get("uris");
	if (uris != null) {
		try {
			if (uris.getNodeType() == JsonNodeType.STRING) {
				return new URI(uris.asText());
			} else if (uris.getNodeType() == JsonNodeType.ARRAY) {
				ArrayNode an = (ArrayNode)uris;
				return new URI(an.get(index).asText());
			}
		} catch (URISyntaxException e) {
			throw new RuntimeException("TD with malformed base uris");
		}
	} else {
		throw new RuntimeException("TD without base uris field");
	}
	// should never be reached
	throw new RuntimeException("Unexpected error while retrieving uri at index " + index);
}
 
開發者ID:thingweb,項目名稱:thingweb,代碼行數:19,代碼來源:Thing.java

示例3: parseJSON

private void parseJSON() throws SchemaConfigurationError {
    try {
        ObjectNode fields = (ObjectNode) root.get("fields");
        Iterator<Map.Entry<String, JsonNode>> iterator = fields.fields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> entry = iterator.next();
            FieldIndex index = buildField(entry.getKey(), entry.getValue());
            schema.addFieldIndex(index.getName(), index);
        }
        JsonNode persistence = root.get("persistence");
        //as a default set DummyQueryStorage. Only if persistence options are provided overwrite it
        schema.setQueryStorage(new DummyQueryStorage());
        if (persistence != null && persistence.getNodeType() == JsonNodeType.OBJECT) {
            //if persistence key doesn't exist there is no persistence
            JsonNode file = persistence.get("file");
            if (file != null && file.getNodeType() == JsonNodeType.STRING) {
                schema.setQueryStorage(new MapDBStore(new File(schemaDirectory, file.asText())));
            } else {
                LOGGER.error("unable to get file name for query storage. Continuing with no persistence!");
            }
        }
    } catch (Exception e) {
        throw new SchemaConfigurationError("Could not parse JSON tree", e);
    }
    schema.init();
}
 
開發者ID:dbasedow,項目名稱:prospecter,代碼行數:26,代碼來源:SchemaBuilderJSON.java

示例4: readStringArray

private List<String> readStringArray(JsonNode rootNode, int position) throws MessageParseException
{
    JsonNode arrayNode = rootNode.get(position);
    if (null == arrayNode || JsonNodeType.ARRAY != arrayNode.getNodeType()) {
        throw new MessageParseException("Expected array at position " + position);
    }

    List<String> stringList = new ArrayList<String>();
    Iterator<JsonNode> elements = arrayNode.elements();
    int iteratorPosition = 0;
    while(elements.hasNext()) {
        JsonNode element = elements.next();
        if (JsonNodeType.STRING != element.getNodeType()) {
            throw new MessageParseException("Array-Item at position " + iteratorPosition + " is no string");
        }
        String stringifiedElement = element.asText();
        if (0 == stringifiedElement.length()) {
            throw new MessageParseException("Array-Item as position " + iteratorPosition + " may not be empty");
        }
        stringList.add(stringifiedElement);
        iteratorPosition++;
    }

    return stringList;
}
 
開發者ID:fritz-gerneth,項目名稱:java-wamp-server,代碼行數:25,代碼來源:PublishMessageConverter.java

示例5: toRS

public static Object toRS(JsonNode value) {
    if (value.getNodeType() == JsonNodeType.STRING) {
        return value.asText();
    } else if (value.getNodeType() == JsonNodeType.NUMBER) {
        if (value.numberType() == JsonParser.NumberType.INT) {
            return value.asInt();
        } else if (value.numberType() == JsonParser.NumberType.LONG) {
            return value.asLong();
        } else if (value.numberType() == JsonParser.NumberType.DOUBLE) {
            return value.asDouble();
        }
    } else if (value.getNodeType() == JsonNodeType.BOOLEAN) {
        return value.asBoolean();
    } else if ( value instanceof ArrayNode ) {
        List<Object> array = new ArrayList<Object>();
        value.elements().forEachRemaining( (e)->{
            array.add( toRS( e ) );
        });
        return array;
    } else if (value instanceof ObjectNode) {
        return convert( (ObjectNode) value );
    }
    return null;
}
 
開發者ID:liveoak-io,項目名稱:liveoak,代碼行數:24,代碼來源:ConversionUtils.java

示例6: parseDtmfFromUserInfo

private String parseDtmfFromUserInfo(JsonNode userInfo) {

    if (userInfo.get("dtmf").getNodeType() == JsonNodeType.STRING) {
      String dtmf = userInfo.get("dtmf").asText();
      int indexOfPound = dtmf.indexOf("#");
      if (indexOfPound != -1) {
        dtmf = dtmf.substring(0, indexOfPound);
      }

      return dtmf;
    }

    return null;
  }
 
開發者ID:Nexmo,項目名稱:comms-router,代碼行數:14,代碼來源:IvrStrategyWithSimpleFlow.java

示例7: parseStringParamFromUserInfo

private String parseStringParamFromUserInfo(JsonNode userInfo, String paramName) {
  if (null == userInfo || null == paramName) {
    return null;
  }

  if (userInfo.get(paramName).getNodeType() == JsonNodeType.STRING) {
    String value = userInfo.get(paramName).asText();
    return value;
  }

  return null;
}
 
開發者ID:Nexmo,項目名稱:comms-router,代碼行數:12,代碼來源:IvrStrategyWithSimpleFlow.java

示例8: parseDtmfFromUserInfo

private String parseDtmfFromUserInfo(JsonNode userInfo) {

    if (userInfo.get("dtmf").getNodeType() == JsonNodeType.STRING) {
      String dtmf = userInfo.get("dtmf").asText();
      int indexOfPound = dtmf.indexOf("#");
      if ( indexOfPound != -1) {
        dtmf = dtmf.substring(0, indexOfPound);
      }

      return dtmf;
    }

    return null;
  }
 
開發者ID:Nexmo,項目名稱:comms-router,代碼行數:14,代碼來源:AnswerStrategyWithCallback.java

示例9: parseRecordingUrlFromUserInfo

private String parseRecordingUrlFromUserInfo(JsonNode userInfo) {

    if (userInfo.get("recording_url").getNodeType() == JsonNodeType.STRING) {
      String url = userInfo.get("recording_url").asText();
      return url;
    }

    return null;
  }
 
開發者ID:Nexmo,項目名稱:comms-router,代碼行數:9,代碼來源:AnswerStrategyWithCallback.java

示例10: createObjectModel

private void createObjectModel(JsonNode node, ModelBuilder modelBuilder, String apiName) {
	Iterator<String> fieldNames = node.fieldNames();

	while (fieldNames.hasNext()) {
		String field = fieldNames.next();
		JsonNode leafNode = node.get(field);

		if (leafNode.getNodeType() == JsonNodeType.NUMBER) {
			if (leafNode.isInt() || leafNode.isLong()) {
				modelBuilder.withIntegerPropertyNamed(field).withExample(leafNode.asLong());
			} else if (leafNode.isFloat() || leafNode.isDouble()) {
				modelBuilder.withNumberPropertyNamed(field).withExample(leafNode.asDouble());
			}
		} else if (leafNode.getNodeType() == JsonNodeType.BOOLEAN) {
			modelBuilder.withBooleanPropertyNamed(field).withExample(leafNode.asBoolean());
		} else if (leafNode.getNodeType() == JsonNodeType.STRING) {
			modelBuilder.withStringPropertyNamed(field).withExample(leafNode.asText());
		} else if (leafNode.getNodeType() == JsonNodeType.OBJECT) {
			String refName = apiName+"-"+field;
			modelBuilder.withReferencePropertyNamed(field).withReferenceTo(refName);
			ModelBuilder objModelBuilder = new ModelBuilder();
			createObjectModel(leafNode, objModelBuilder, refName);
			models.put(refName, objModelBuilder);
		}else if(leafNode.getNodeType() == JsonNodeType.ARRAY){
			createArrayModel(leafNode, modelBuilder.withArrayProperty(field), apiName+"-"+field);				
		}
	}		
}
 
開發者ID:pegasystems,項目名稱:api2swagger,代碼行數:28,代碼來源:SwaggerModelGenerator.java

示例11: isXmlSchemaType

public static boolean isXmlSchemaType(JsonNode type) {
	boolean isXsd = false;
	
	if (type != null && type.getNodeType() == JsonNodeType.STRING) {
		// very naive and simple for now
		isXsd = type.asText().trim().startsWith("xsd:");
	}

	return isXsd;
}
 
開發者ID:thingweb,項目名稱:thingweb,代碼行數:10,代碼來源:TypeSystemChecker.java

示例12: getStopWords

protected static CharArraySet getStopWords(JsonNode stopWords, CharArraySet defaultStopWords) {
    CharArraySet stopWordSet = new CharArraySet(Version.LUCENE_4_9, 5, true);
    if (stopWords != null) {
        if (stopWords.getNodeType() == JsonNodeType.ARRAY) {
            for (JsonNode node : stopWords) {
                if (node != null && node.getNodeType() == JsonNodeType.STRING) {
                    stopWordSet.add(node.asText());
                }
            }
        } else if (stopWords.getNodeType() == JsonNodeType.STRING && "predefined".equals(stopWords.asText())) {
            stopWordSet = defaultStopWords;
        }
    }
    return stopWordSet;
}
 
開發者ID:dbasedow,項目名稱:prospecter,代碼行數:15,代碼來源:LuceneAnalyzer.java

示例13: handleStringField

private Field handleStringField(String fieldName, JsonNode node) {
    List<Token> tokens = new ArrayList<Token>();
    if (node.getNodeType() == JsonNodeType.ARRAY) {
        Iterator<JsonNode> iterator = ((ArrayNode) node).elements();
        while (iterator.hasNext()) {
            JsonNode subNode = iterator.next();
            if (subNode.getNodeType() == JsonNodeType.STRING) {
                tokens.add(new Token<String>(subNode.asText()));
            }
        }
    } else if (node.getNodeType() == JsonNodeType.STRING) {
        tokens.add(new Token<String>(node.asText()));
    }
    return new Field(fieldName, tokens);
}
 
開發者ID:dbasedow,項目名稱:prospecter,代碼行數:15,代碼來源:DocumentBuilder.java

示例14: getAnalyzer

private Analyzer getAnalyzer(JsonNode options) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    String analyzerName = "de.danielbasedow.prospecter.core.analysis.LuceneStandardAnalyzer";
    if (options != null && options.getNodeType() == JsonNodeType.OBJECT) {
        JsonNode analyzerNode = options.get("analyzer");
        if (analyzerNode != null && analyzerNode.getNodeType() == JsonNodeType.STRING) {
            analyzerName = analyzerNode.asText();
        }
    }
    LOGGER.info("using analyzer " + analyzerName);
    Class class_ = Class.forName(analyzerName);
    Method factory = class_.getMethod("make", JsonNode.class);
    return (Analyzer) factory.invoke(null, options);
}
 
開發者ID:dbasedow,項目名稱:prospecter,代碼行數:13,代碼來源:SchemaBuilderJSON.java

示例15: deserialize

@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;
}
 
開發者ID:intercom,項目名稱:intercom-java,代碼行數:32,代碼來源:CustomAttributeDeserializer.java


注:本文中的com.fasterxml.jackson.databind.node.JsonNodeType.STRING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。