Java 类com.fasterxml.jackson.databind.node.DecimalNode 实例源码

项目:dataplatform-schema-lib    文件:JsonNodeToPrimitiveObject.java   
public static PrimitiveObject get( final JsonNode jsonNode ) throws IOException{
  if( jsonNode instanceof TextNode ){
    return new StringObj( ( (TextNode)jsonNode ).textValue() );
  }
  else if( jsonNode instanceof BooleanNode ){
    return new BooleanObj( ( (BooleanNode)jsonNode ).booleanValue() );
  }
  else if( jsonNode instanceof IntNode ){
    return new IntegerObj( ( (IntNode)jsonNode ).intValue() );
  }
  else if( jsonNode instanceof LongNode ){
    return new LongObj( ( (LongNode)jsonNode ).longValue() );
  }
  else if( jsonNode instanceof DoubleNode ){
    return new DoubleObj( ( (DoubleNode)jsonNode ).doubleValue() );
  }
  else if( jsonNode instanceof BigIntegerNode ){
    return new StringObj( ( (BigIntegerNode)jsonNode ).bigIntegerValue().toString() );
  }
  else if( jsonNode instanceof DecimalNode ){
    return new StringObj( ( (DecimalNode)jsonNode ).decimalValue().toString() );
  }
  else if( jsonNode instanceof BinaryNode ){
    return new BytesObj( ( (BinaryNode)jsonNode ).binaryValue() );
  }
  else if( jsonNode instanceof POJONode ){
    return new BytesObj( ( (POJONode)jsonNode ).binaryValue() );
  }
  else if( jsonNode instanceof NullNode ){
    return NullObj.getInstance();
  }
  else if( jsonNode instanceof MissingNode ){
    return NullObj.getInstance();
  }
  else{
    return new StringObj( jsonNode.toString() );
  }
}
项目:template-compiler    文件:Instructions.java   
private static void emitJsonNode(StringBuilder buf, JsonNode node) {
  if (node.isNumber()) {
    // Formatting of numbers depending on type
    switch (node.numberType()) {
      case BIG_INTEGER:
        buf.append(((BigIntegerNode)node).bigIntegerValue().toString());
        break;

      case BIG_DECIMAL:
        buf.append(((DecimalNode)node).decimalValue().toPlainString());
        break;

      case INT:
      case LONG:
        buf.append(node.asLong());
        break;

      case FLOAT:
      case DOUBLE:
        double val = node.asDouble();
        buf.append(Double.toString(val));
        break;

      default:
        break;
    }

  } else if (node.isArray()) {
    // JavaScript Array.toString() will comma-delimit the elements.
    for (int i = 0, size = node.size(); i < size; i++) {
      if (i >= 1) {
        buf.append(",");
      }
      buf.append(node.path(i).asText());
    }

  } else if (!node.isNull() && !node.isMissingNode()) {
    buf.append(node.asText());
  }
}
项目:template-compiler    文件:DecimalFormatterTest.java   
private void run(CLDR.Locale locale, String number, String args, String expected) {
  try {
    String json = new DecimalNode(new BigDecimal(number)).toString();
    String actual = format(locale, mk.args(args), json);
    Assert.assertEquals(actual, expected);
  } catch (CodeException e) {
    fail("formatter raised an error", e);
  }
}
项目:unravl    文件:Json.java   
public static Object unwrap(Object val) { // Can Jackson do this via
                                          // ObjectMapper.treeToValue()? The
                                          // spec is unclear
    Object result = val;
    ObjectMapper mapper = new ObjectMapper();
    if (val instanceof ObjectNode) {
        result = mapper.convertValue((ObjectNode) val, Map.class);
    } else if (val instanceof ArrayNode) {
        result = mapper.convertValue((ObjectNode) val, List.class);
    } else if (val instanceof NullNode) {
        result = null;
    } else if (val instanceof BooleanNode) {
        result = ((BooleanNode) val).booleanValue();
    } else if (val instanceof ShortNode) {
        result = ((ShortNode) val).shortValue();
    } else if (val instanceof IntNode) {
        result = ((IntNode) val).intValue();
    } else if (val instanceof LongNode) {
        result = ((LongNode) val).longValue();
    } else if (val instanceof DoubleNode) {
        result = ((DoubleNode) val).doubleValue();
    } else if (val instanceof FloatNode) {
        result = ((FloatNode) val).floatValue();
    } else if (val instanceof BigIntegerNode) {
        result = ((BigIntegerNode) val).bigIntegerValue();
    } else if (val instanceof DecimalNode) {
        result = ((DecimalNode) val).decimalValue();
    }
    return result;
}
项目:redson    文件:JsonNumber.java   
@Override
public JsonNode toJsonNode() {
    return DecimalNode.valueOf(value);
}