本文整理汇总了Java中com.fasterxml.jackson.databind.node.NumericNode类的典型用法代码示例。如果您正苦于以下问题:Java NumericNode类的具体用法?Java NumericNode怎么用?Java NumericNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NumericNode类属于com.fasterxml.jackson.databind.node包,在下文中一共展示了NumericNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compare
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
@Override
public int compare(JsonNode o1, JsonNode o2) {
if (o1.equals(o2)) {
return 0;
}
if ((o1 instanceof NumericNode) && (o2 instanceof NumericNode)) {
double d1 = ((NumericNode) o1).asDouble();
double d2 = ((NumericNode) o2).asDouble();
return Double.compare(d1, d2);
}
int comp = o1.asText().compareTo(o2.asText());
if (comp == 0) {
return Integer.compare(o1.hashCode(), o2.hashCode());
}
return comp;
}
示例2: jsonNumber
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
public static Matcher<JsonNode> jsonNumber(final NumericNode value) {
final JsonParser.NumberType numberType = value.numberType();
switch (numberType) {
case INT:
return jsonInt(value.asInt());
case LONG:
return jsonLong(value.asLong());
case BIG_INTEGER:
return jsonBigInteger(value.bigIntegerValue());
case FLOAT:
return jsonFloat(value.floatValue());
case DOUBLE:
return jsonDouble(value.doubleValue());
case BIG_DECIMAL:
return jsonBigDecimal(value.decimalValue());
default:
throw new UnsupportedOperationException("Unsupported number type " + numberType);
}
}
示例3: valueFromJson
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
/**
* Returns a Java object for a json value node based on the node type.
*/
public static Object valueFromJson(ValueNode node) {
if (node instanceof NullNode) {
return null;
} else {
if(node instanceof TextNode) {
return node.textValue();
} else if(node instanceof BooleanNode) {
return node.booleanValue();
} else if(node instanceof NumericNode) {
return node.numberValue();
} else {
throw new RuntimeException("Unsupported node type:"+node.getClass().getName());
}
}
}
示例4: deserialize
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
@Override
public RTimeSeriesData deserialize(JsonParser jp, DeserializationContext ctx) throws IOException {
final TreeNode node = jp.getCodec().readTree(jp);
final HashMap<RMeasure, Double> data = new HashMap<>();
node.fieldNames().forEachRemaining(field -> {
if (!field.equals("date")) {
final RMeasure key = RMeasure.fromId(field);
final double value = ((NumericNode) node.get(field)).doubleValue();
data.put(key, value);
}
});
return new RTimeSeriesData(ctx.parseDate(((TextNode) node.get("date")).textValue()), data);
}
示例5: deserialize
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
@Override
public TimeSeriesItem deserialize(JsonParser jp, DeserializationContext ctx) throws IOException {
final TreeNode node = jp.getCodec().readTree(jp);
final Measure[] measure = new Measure[1];
final Double[] value = new Double[1];
node.fieldNames().forEachRemaining(field -> {
if (!field.equals("date")) {
measure[0] = Measure.fromId(field);
value[0] = ((NumericNode) node.get(field)).doubleValue();
}
});
return new TimeSeriesItem(ctx.parseDate(((TextNode) node.get("date")).textValue()), measure[0], value[0]);
}
示例6: numerify
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
/**
* Converts the passed object to a JSON numeric node
* @param number A {@link Number} or a string representing one
* @return A JSON Numeric Node
*/
public static NumericNode numerify(Object number) {
if(number==null) throw new IllegalArgumentException("Passed number was null");
//if(!(number instanceof Number)) throw new IllegalArgumentException("The passed object [" + number + "] is not a number");
String s = number.toString();
if(s.indexOf('.')!=-1) {
return jsonNodeFactory.numberNode(new BigDecimal(s));
}
return jsonNodeFactory.numberNode(Long.parseLong(s));
}
示例7: matchesNode
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
@Override
protected boolean matchesNode(NumericNode node, Description mismatchDescription) {
final Object number = projection.apply(node);
if (numberMatcher.matches(number)) {
return true;
} else {
mismatchDescription.appendText("was a number node with value that ");
numberMatcher.describeMismatch(number, mismatchDescription);
return false;
}
}
示例8: createNodeMatcher
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
private static Matcher<JsonNode> createNodeMatcher(final JsonNode value) {
final JsonNodeType nodeType = value.getNodeType();
switch (nodeType) {
case ARRAY:
return IsJsonArray.jsonArray((ArrayNode) value);
case BINARY:
throw new UnsupportedOperationException(
"Expected value contains a binary node, which is not implemented.");
case BOOLEAN:
return IsJsonBoolean.jsonBoolean((BooleanNode) value);
case MISSING:
return IsJsonMissing.jsonMissing((MissingNode) value);
case NULL:
return IsJsonNull.jsonNull((NullNode) value);
case NUMBER:
return IsJsonNumber.jsonNumber((NumericNode) value);
case OBJECT:
return IsJsonObject.jsonObject((ObjectNode) value);
case POJO:
throw new UnsupportedOperationException(
"Expected value contains a POJO node, which is not implemented.");
case STRING:
return IsJsonText.jsonText((TextNode) value);
default:
throw new UnsupportedOperationException("Unsupported node type " + nodeType);
}
}
示例9: deserialize
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
/**
* Deserialize.
*
* @param node the node
* @return the json element
*/
@SuppressWarnings("unchecked")
private T deserialize(JsonNode node) {
JsonElement result = JsonNull.INSTANCE;
if (null != node && !node.isNull()) {
if (node.isObject()) {
ObjectNode onode = (ObjectNode) node;
JsonObject jsonObject = new JsonObject();
Iterator<Entry<String, JsonNode>> fields = onode.fields();
while (fields.hasNext()) {
Entry<String, JsonNode> next = fields.next();
jsonObject.add(next.getKey(), deserialize(next.getValue()));
}
result = jsonObject;
} else if (node.isArray()) {
ArrayNode anode = (ArrayNode) node;
JsonArray jsonArray = new JsonArray();
Iterator<JsonNode> elements = anode.elements();
while (elements.hasNext()) {
jsonArray.add(deserialize(elements.next()));
}
result = jsonArray;
} else if (node.isBoolean()) {
result = new JsonPrimitive(node.asBoolean());
} else if (node.isNumber()) {
NumericNode nnode = (NumericNode) node;
result = new JsonPrimitive(nnode.numberValue());
} else if (node.isTextual()) {
TextNode tnode = (TextNode) node;
result = new JsonPrimitive(tnode.textValue());
}
}
return (T) result;
}
示例10: getQuantity
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
protected BigInteger getQuantity(JsonNode node) {
if (node instanceof NumericNode) {
return BigInteger.valueOf(node.longValue());
}
String value = getHexString(node);
if (value == null) return null;
return HexEncoding.fromHex(value);
}
示例11: nodeToBigDecimal
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
/**
* 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;
}
示例12: numericToBigDecimal
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
/**
* Convert a numeric JSON node to BigDecimal using the most correct
* conversion method.
*/
private static BigDecimal numericToBigDecimal(NumericNode node) {
switch (node.numberType()) {
case INT:
case LONG:
return BigDecimal.valueOf(node.asLong());
case FLOAT:
case DOUBLE:
return BigDecimal.valueOf(node.asDouble());
case BIG_DECIMAL:
case BIG_INTEGER:
default:
return node.decimalValue();
}
}
示例13: InvocationMessage
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
public InvocationMessage(long requestID, NumericNode registrationID, ObjectNode details, ArrayNode arguments, ObjectNode argumentsKw){
this.requestID = requestID;
this.registrationID = registrationID;
this.details = details;
this.arguments = arguments;
this.argumentsKw = argumentsKw;
}
示例14: deserialize
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
@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;
}
示例15: nextSibling_ArrayNode
import com.fasterxml.jackson.databind.node.NumericNode; //导入依赖的package包/类
@Test
public void nextSibling_ArrayNode() throws IOException {
String jsonString = "{\"x\":[1,2,3,4]}";
JsonNode node = JsonUtils.json(jsonString);
JsonNodeCursor c = new JsonNodeCursor(new Path(""), node);
Assert.assertTrue(c.firstChild());
Assert.assertTrue(c.firstChild());
Assert.assertNotNull(c.getCurrentNode());
Assert.assertTrue(c.getCurrentNode() instanceof NumericNode);
Assert.assertEquals("x.0", c.getCurrentPath().toString());
}