/** * Method that will try to convert value of this node to a Java <b>long</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an long (including structured types * like Objects and Arrays), * default value of <b>0</b> will be returned; no exceptions are thrown. * * @since 1.9 (replaces <code>getValueAsLong</code>) */ public long asLong() { return asLong(0L); }
/** * Method that will try to convert value of this node to a Java <b>long</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an long (including structured types * like Objects and Arrays), * default value of <b>0</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asLong} instead */ @Deprecated public long getValueAsLong() { return asLong(0L); }
/** * Method that will try to convert value of this node to a Java <b>long</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an long (including structured types * like Objects and Arrays), * specified <b>defaultValue</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asLong} instead */ @Deprecated public long getValueAsLong(long defaultValue) { return asLong(defaultValue); }
private void assertQueryGetsValue( ServerControls server, String query, long value ) throws Throwable { HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(), quotedJson( "{ 'statements': [ { 'statement': '" + query + "' } ] }" ) ); assertEquals( "[]", response.get( "errors" ).toString() ); JsonNode result = response.get( "results" ).get( 0 ); assertEquals( "value", result.get( "columns" ).get( 0 ).asText() ); assertEquals( value, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asLong() ); }
private void assertQueryGetsValue( ServerControls server, String query, long value ) throws Throwable { HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(), quotedJson( "{ 'statements': [ { 'statement': '" + query + "' } ] }" ) ); assertEquals( "[]", response.get( "errors" ).toString() ); JsonNode result = response.get( "results" ).get( 0 ); assertEquals( "value", result.get( "columns" ).get( 0 ).asText() ); assertEquals( value, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asLong() ); }
return node.asInt(); } else if (node.isLong()) { return node.asLong(); } else if (node.isDouble()) { return node.asDouble();
/** * Method that will try to convert value of this node to a Java <b>long</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an long (including structured types * like Objects and Arrays), * default value of <b>0</b> will be returned; no exceptions are thrown. * * @since 1.9 (replaces <code>getValueAsLong</code>) */ public long asLong() { return asLong(0L); }
assertEquals( 0, root.get( "id" ).asLong() ); assertEquals( asSet( parentId ), identifiersOf( root ) );
/** * Method that will try to convert value of this node to a Java <b>long</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an long (including structured types * like Objects and Arrays), * specified <b>defaultValue</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asLong} instead */ @Deprecated public long getValueAsLong(long defaultValue) { return asLong(defaultValue); }
/** * Method that will try to convert value of this node to a Java <b>long</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an long (including structured types * like Objects and Arrays), * default value of <b>0</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asLong} instead */ @Deprecated public long getValueAsLong() { return asLong(0L); }
return byDefault.asLong();
public long asLong(final long defaultValue) { return delegate.asLong(defaultValue); }
public long asLong() { return delegate.asLong(); }
public static String setYeAmountToJson(String date) throws JsonProcessingException, IOException{ JsonNode dataNode = mapper.readTree(date); for(JsonNode node:dataNode){ ((ObjectNode)node).put("extrafield1",node.get("mertrademoney").asLong()-node.get("tradeamount").asLong()); } return dataNode.toString(); } public static JsonNode dataToJson(String data) throws JsonProcessingException, IOException{
private final ObjectId processSplinteredId(final JsonNode treeNode) { final long time = treeNode.get("time").asLong(); final int machine = treeNode.get("machine").asInt(); final int inc = treeNode.get("inc").asInt(); final ObjectId objectId = new ObjectId(new Date(time), machine, inc); objectId.notNew(); return objectId; } }
public static String jsonLongTimeToDate(String data,String timedata) throws JsonProcessingException, IOException{ ObjectMapper mapper = new ObjectMapper(); JsonNode dataNode = mapper.readTree(data); String []time = timedata.split(","); for (JsonNode jsonNode : dataNode) { for (String str : time) { ((ObjectNode)jsonNode).put(str, (jsonNode.get(str)==null||"".equals(jsonNode.get(str).asText()))?"1970-01-01":DateUtil.format(new Date(jsonNode.get(str).asLong()),DateStyle.YYYY_MM_DD)); } } return dataNode.toString(); }
@Override public ObjectId deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { final ObjectCodec codec = jsonParser.getCodec(); final JsonNode treeNode = codec.readTree(jsonParser); final long time = treeNode.get("time").asLong(); final int machine = treeNode.get("machine").asInt(); final int inc = treeNode.get("inc").asInt(); final ObjectId objectId = new ObjectId(new Date(time), machine, inc); objectId.notNew(); return objectId; } }
@Override public long follow(String trendName) { requireAuthorization(); MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>( 1); request.add("trend_name", trendName); return restTemplate .postForObject(buildUri("trends/follow.json"), request, JsonNode.class).findValue("topicid").asLong(); }
@Override protected LongBuffer deserialize(final ArrayNode input) throws JsonProcessingException { final LongBuffer result = LongBuffer.allocate(input.size()); for(final JsonNode node: input) result.put(node.asLong()); return result; } }