类com.fasterxml.jackson.databind.node.BigIntegerNode源码实例Demo

下面列出了怎么用com.fasterxml.jackson.databind.node.BigIntegerNode的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: yosegi   文件: JsonNodeToPrimitiveObject.java
/**
 * Converts JsonNode to PrimitiveObject.
 */
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() );
  }
}
 
源代码2 项目: jslt   文件: StaticTests.java
@Test
public void testIsIntegerFunction() {
  // check that is-integer still works if input
  // is a BigIntegerNode not just IntNode
  Expression expr = Parser.compileString("is-integer(.)");

  JsonNode context = new BigIntegerNode(BigInteger.ONE);
  JsonNode actual = expr.apply(context);

  assertTrue(actual.isBoolean());
  assertTrue(actual.booleanValue());
}
 
源代码3 项目: graphql-spqr   文件: JacksonScalars.java
@Override
public Number serialize(Object dataFetcherResult) {
    if (dataFetcherResult instanceof BigIntegerNode) {
        return ((BigIntegerNode) dataFetcherResult).numberValue();
    } else {
        throw serializationException(dataFetcherResult, BigIntegerNode.class);
    }
}
 
源代码4 项目: graphql-spqr   文件: JacksonScalars.java
@Override
public BigIntegerNode parseValue(Object input) {
    if (input instanceof Number || input instanceof String) {
        return BigIntegerNode.valueOf(new BigInteger(input.toString()));
    }
    if (input instanceof BigIntegerNode) {
        return (BigIntegerNode) input;
    }
    throw valueParsingException(input, Number.class, String.class, BigIntegerNode.class);
}
 
源代码5 项目: graphql-spqr   文件: JacksonScalars.java
@Override
public BigIntegerNode parseLiteral(Object input) {
    if (input instanceof IntValue) {
        return BigIntegerNode.valueOf(((IntValue) input).getValue());
    } else {
        throw new CoercingParseLiteralException(errorMessage(input, IntValue.class));
    }
}
 
源代码6 项目: graphql-spqr   文件: JacksonScalars.java
private static Map<Type, GraphQLScalarType> getScalarMapping() {
    Map<Type, GraphQLScalarType> scalarMapping = new HashMap<>();
    scalarMapping.put(TextNode.class, JsonTextNode);
    scalarMapping.put(BooleanNode.class, JsonBooleanNode);
    scalarMapping.put(BinaryNode.class, JsonBinaryNode);
    scalarMapping.put(BigIntegerNode.class, JsonBigIntegerNode);
    scalarMapping.put(IntNode.class, JsonIntegerNode);
    scalarMapping.put(ShortNode.class, JsonShortNode);
    scalarMapping.put(DecimalNode.class, JsonDecimalNode);
    scalarMapping.put(FloatNode.class, JsonFloatNode);
    scalarMapping.put(DoubleNode.class, JsonDoubleNode);
    scalarMapping.put(NumericNode.class, JsonDecimalNode);
    return Collections.unmodifiableMap(scalarMapping);
}
 
源代码7 项目: graphql-spqr   文件: JsonTypeMappingTest.java
public JacksonContainer(ObjectNode obj, JsonNode any, BinaryNode binary, TextNode text, IntNode integer,
                        DoubleNode dbl, BigIntegerNode bigInt, ArrayNode array) {
    this.obj = obj;
    this.any = any;
    this.text = text;
    this.binary = binary;
    this.integer = integer;
    this.dbl = dbl;
    this.bigInt = bigInt;
    this.array = array;
}
 
源代码8 项目: 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());
  }
}
 
private Example createExample(JsonNode node) {
    if (node instanceof ObjectNode) {
        ObjectExample obj = new ObjectExample();
        ObjectNode on = (ObjectNode) node;
        for (Iterator<Entry<String, JsonNode>> x = on.fields(); x.hasNext(); ) {
            Entry<String, JsonNode> i = x.next();
            String key = i.getKey();
            JsonNode value = i.getValue();
            obj.put(key, createExample(value));
        }
        return obj;
    } else if (node instanceof ArrayNode) {
        ArrayExample arr = new ArrayExample();
        ArrayNode an = (ArrayNode) node;
        for (JsonNode childNode : an) {
            arr.add(createExample(childNode));
        }
        return arr;
    } else if (node instanceof DoubleNode) {
        return new DoubleExample(node.doubleValue());
    } else if (node instanceof IntNode || node instanceof ShortNode) {
        return new IntegerExample(node.intValue());
    } else if (node instanceof FloatNode) {
        return new FloatExample(node.floatValue());
    } else if (node instanceof BigIntegerNode) {
        return new BigIntegerExample(node.bigIntegerValue());
    } else if (node instanceof DecimalNode) {
        return new DecimalExample(node.decimalValue());
    } else if (node instanceof LongNode) {
        return new LongExample(node.longValue());
    } else if (node instanceof BooleanNode) {
        return new BooleanExample(node.booleanValue());
    } else {
        return new StringExample(node.asText());
    }
}
 
源代码10 项目: yosegi   文件: TestJsonNodeToPrimitiveObject.java
@Test
public void T_get_bigIntegerObject() throws IOException {
  PrimitiveObject obj = JsonNodeToPrimitiveObject.get( BigIntegerNode.valueOf( new BigInteger( "100" ) ) );
  assertTrue( ( obj instanceof StringObj ) );
}
 
源代码11 项目: jslt   文件: NodeUtils.java
private static JsonNode parseNumber(String number) {
  if (number.length() == 0)
    return null;

  int pos = 0;
  if (number.charAt(0) == '-') {
    pos = 1;
  }

  int endInteger = scanDigits(number, pos);
  if (endInteger == pos)
    return null;
  if (endInteger == number.length()) {
    if (number.length() < 10)
      return new IntNode(Integer.parseInt(number));
    else if (number.length() < 19)
      return new LongNode(Long.parseLong(number));
    else
      return new BigIntegerNode(new BigInteger(number));
  }

  // since there's stuff after the initial integer it must be either
  // the decimal part or the exponent
  int intPart = Integer.parseInt(number.substring(0, endInteger));
  pos = endInteger;
  double value = intPart;

  if (number.charAt(pos) == '.') {
    pos += 1;
    int endDecimal = scanDigits(number, pos);
    if (endDecimal == pos)
      return null;

    long decimalPart = Long.parseLong(number.substring(endInteger + 1, endDecimal));
    int digits = endDecimal - endInteger - 1;

    value = (decimalPart / Math.pow(10, digits)) + intPart;
    pos = endDecimal;

    // if there's nothing more, then this is it
    if (pos == number.length())
      return new DoubleNode(value);
  }

  // there is more: next character MUST be 'e' or 'E'
  char ch = number.charAt(pos);
  if (ch != 'e' && ch != 'E')
    return null;

  // now we must have either '-', '+', or an integer
  pos++;
  if (pos == number.length())
    return null;
  ch = number.charAt(pos);
  int sign = 1;
  if (ch == '+')
    pos++;
  else if (ch == '-') {
    sign = -1;
    pos++;
  }

  int endExponent = scanDigits(number, pos);
  if (endExponent != number.length() || endExponent == pos)
    return null;

  int exponent = Integer.parseInt(number.substring(pos)) * sign;
  return new DoubleNode(value * Math.pow(10, exponent));
}
 
源代码12 项目: graphql-spqr   文件: JsonTypeMappingTest.java
public BigIntegerNode getBigInt() {
    return bigInt;
}
 
源代码13 项目: java-hamcrest   文件: IsJsonNumberTest.java
@Test
public void testLiteralBigInteger() throws Exception {
  final Matcher<JsonNode> sut = jsonNumber(BigIntegerNode.valueOf(BigInteger.ONE));

  assertThat(NF.numberNode(BigInteger.ONE), is(sut));
}
 
源代码14 项目: onos   文件: DistributedWorkplaceStore.java
@Activate
public void activate() {

    appId = coreService.registerApplication("org.onosproject.workplacestore");
    log.info("appId=" + appId);

    KryoNamespace workplaceNamespace = KryoNamespace.newBuilder()
            .register(KryoNamespaces.API)
            .register(WorkflowData.class)
            .register(Workplace.class)
            .register(DefaultWorkplace.class)
            .register(WorkflowContext.class)
            .register(DefaultWorkflowContext.class)
            .register(SystemWorkflowContext.class)
            .register(WorkflowState.class)
            .register(ProgramCounter.class)
            .register(DataModelTree.class)
            .register(JsonDataModelTree.class)
            .register(List.class)
            .register(ArrayList.class)
            .register(JsonNode.class)
            .register(ObjectNode.class)
            .register(TextNode.class)
            .register(LinkedHashMap.class)
            .register(ArrayNode.class)
            .register(BaseJsonNode.class)
            .register(BigIntegerNode.class)
            .register(BinaryNode.class)
            .register(BooleanNode.class)
            .register(ContainerNode.class)
            .register(DecimalNode.class)
            .register(DoubleNode.class)
            .register(FloatNode.class)
            .register(IntNode.class)
            .register(JsonNodeType.class)
            .register(LongNode.class)
            .register(MissingNode.class)
            .register(NullNode.class)
            .register(NumericNode.class)
            .register(POJONode.class)
            .register(ShortNode.class)
            .register(ValueNode.class)
            .register(JsonNodeCreator.class)
            .register(JsonNodeFactory.class)
            .build();

    localWorkplaceMap.clear();
    workplaceMap = storageService.<String, WorkflowData>consistentMapBuilder()
            .withSerializer(Serializer.using(workplaceNamespace))
            .withName("workplace-map")
            .withApplicationId(appId)
            .build();
    workplaceMap.addListener(workplaceMapEventListener);

    localContextMap.clear();
    contextMap = storageService.<String, WorkflowData>consistentMapBuilder()
            .withSerializer(Serializer.using(workplaceNamespace))
            .withName("workflow-context-map")
            .withApplicationId(appId)
            .build();
    contextMap.addListener(contextMapEventListener);

    workplaceMapEventListener.syncLocal();
    contextMapEventListener.syncLocal();
    log.info("Started");
}
 
 类方法
 同包方法