本文整理匯總了Java中com.fasterxml.jackson.databind.node.JsonNodeType.NUMBER屬性的典型用法代碼示例。如果您正苦於以下問題:Java JsonNodeType.NUMBER屬性的具體用法?Java JsonNodeType.NUMBER怎麽用?Java JsonNodeType.NUMBER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類com.fasterxml.jackson.databind.node.JsonNodeType
的用法示例。
在下文中一共展示了JsonNodeType.NUMBER屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleIntegerField
/**
* IntegerIndex backed fields are handled here
*
* @param fieldName name of the field
* @param node JsonNode representing the field content. This can be an array or a number
* @return Field instance
*/
private Field handleIntegerField(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.NUMBER) {
tokens.add(new Token<Integer>(subNode.asInt()));
}
}
} else if (node.getNodeType() == JsonNodeType.NUMBER) {
tokens.add(new Token<Integer>(node.asInt()));
}
return new Field(fieldName, tokens);
}
示例2: 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;
}
示例3: 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);
}
}
}
示例4: nodeToBigDecimal
/**
* Convert an opaque JSON node to BigDecimal using the most correct
* conversion method.
*/
public static BigDecimal nodeToBigDecimal(JsonNode node) {
JsonNodeType type = node.getNodeType();
if (type == JsonNodeType.NUMBER) {
return numericToBigDecimal((NumericNode)node);
} else {
try {
return new BigDecimal(node.asText());
} catch (ArithmeticException | NumberFormatException e) {
// Fall through..
}
}
return null;
}
示例5: unmarshall
/**
* Update the content of this object with a JSON structure.<br/>
* NB: selectableColumns are never updated
*
* @param json
* the json node to unmarshall
*/
private void unmarshall(JsonNode json) throws FilterConfigException {
JsonNode currentPageNode = json.get(JSON_CURRENT_PAGE_FIELD);
if (currentPageNode != null && currentPageNode.getNodeType() == JsonNodeType.NUMBER) {
setCurrentPage(((Long) currentPageNode.asLong()).intValue());
if (log.isDebugEnabled()) {
log.debug("Unmarshalled page number : " + getCurrentPage());
}
}
JsonNode userConfigAsJson = json.get(JSON_USER_CONFIG_FIELD);
if (userConfigAsJson != null && userConfigAsJson.getNodeType() == JsonNodeType.OBJECT) {
Iterator<String> fieldNames = userConfigAsJson.fieldNames();
while (fieldNames.hasNext()) {
String columnId = fieldNames.next();
if (getUserColumnConfigurations().containsKey(columnId)) {
UserColumnConfiguration userColumnConfiguration = getUserColumnConfigurations().get(columnId);
JsonNode userColumnConfigurationAsJson = userConfigAsJson.get(columnId);
if (log.isDebugEnabled()) {
log.debug("Unmarshalled json : " + userColumnConfigurationAsJson);
}
userColumnConfiguration.unmarshall(getSelectableColumns().get(columnId), userColumnConfigurationAsJson);
} else {
if (log.isDebugEnabled()) {
log.debug("Unknown column : " + columnId);
}
}
}
}
if (json.has(JSON_SELECTED_ROWS_FIELD) && json.get(JSON_SELECTED_ROWS_FIELD).isArray()) {
this.selectedRows = new ArrayList<>();
for (JsonNode node : json.get(JSON_SELECTED_ROWS_FIELD)) {
this.selectedRows.add(node.asText());
}
}
}
示例6: handleLongField
private Field handleLongField(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.NUMBER) {
tokens.add(new Token<Long>(subNode.asLong()));
}
}
} else if (node.getNodeType() == JsonNodeType.NUMBER) {
tokens.add(new Token<Long>(node.asLong()));
}
return new Field(fieldName, tokens);
}
示例7: handleDoubleField
private Field handleDoubleField(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.NUMBER) {
tokens.add(new Token<Double>(subNode.asDouble()));
}
}
} else if (node.getNodeType() == JsonNodeType.NUMBER) {
tokens.add(new Token<Double>(node.asDouble()));
}
return new Field(fieldName, tokens);
}
示例8: 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;
}
示例9: parseProperties
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");
}
}
}
示例10: readIntAt
protected int readIntAt(JsonNode rootNode, int position) throws MessageParseException
{
JsonNode messageCodeNode = rootNode.get(position);
if (null == messageCodeNode || JsonNodeType.NUMBER != messageCodeNode.getNodeType() || !messageCodeNode.canConvertToInt()) {
throw new MessageParseException("Cannot read integer at position " + position);
}
return messageCodeNode.asInt();
}
示例11: IsJsonNumber
private IsJsonNumber(final Matcher<?> numberMatcher,
final Function<NumericNode, Object> projection) {
super(JsonNodeType.NUMBER);
this.numberMatcher = Objects.requireNonNull(numberMatcher);
this.projection = Objects.requireNonNull(projection);
}
示例12: isNumber
public final boolean isNumber()
{
return getNodeType() == JsonNodeType.NUMBER;
}