Java Code Examples for javax.json.JsonNumber#longValueExact()

The following examples show how to use javax.json.JsonNumber#longValueExact() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonNumberReader.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
private Object read(Location location, JsonNumber value, Class<?> rawType) {
    if (byte.class.equals(rawType) || Byte.class.equals(rawType))
        return (byte) readIntBetween(location, value, Byte.MIN_VALUE, Byte.MAX_VALUE);
    if (char.class.equals(rawType) || Character.class.equals(rawType))
        return (char) readIntBetween(location, value, Character.MIN_VALUE, Character.MAX_VALUE);
    if (short.class.equals(rawType) || Short.class.equals(rawType))
        return (short) readIntBetween(location, value, Short.MIN_VALUE, Short.MAX_VALUE);
    if (int.class.equals(rawType) || Integer.class.equals(rawType))
        return value.intValueExact();
    if (long.class.equals(rawType) || Long.class.equals(rawType))
        return value.longValueExact();
    if (float.class.equals(rawType) || Float.class.equals(rawType))
        return (float) value.doubleValue();
    if (double.class.equals(rawType) || Double.class.equals(rawType))
        return value.doubleValue();
    if (BigInteger.class.equals(rawType))
        return value.bigIntegerValueExact();
    if (BigDecimal.class.equals(rawType))
        return value.bigDecimalValue();

    throw new GraphQlClientValueException(location, value);
}
 
Example 2
Source File: ProviderInjectionEndpoint.java    From microprofile-jwt-auth with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/verifyInjectedCustomInteger")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomInteger(@QueryParam("value") Long value) {
    boolean pass = false;
    String msg;
    // iat
    Object test = customInteger.get();
    System.out.printf("+++ verifyInjectedCustomInteger, JsonNumber.class.CL: %s\n",
        JsonNumber.class.getClassLoader());
    System.out.printf("+++ customInteger.CL: %s\n",
        test.getClass().getClassLoader());
    Class[] ifaces = test.getClass().getInterfaces();
    for(Class iface : ifaces) {
        System.out.printf("%s: %s\n", iface, iface.getClassLoader());
    }
    JsonNumber customValue = JsonNumber.class.cast(test);
    if(customValue == null || customValue.isIntegral() == false) {
        msg = "customInteger value is null or not integral, FAIL";
    }
    else if(customValue.longValueExact() == value) {
        msg = "customInteger PASS";
        pass = true;
    }
    else {
        msg = String.format("customInteger: %d != %d", customValue, value);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
 
Example 3
Source File: ClaimValueInjectionEndpoint.java    From microprofile-jwt-auth with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/verifyInjectedCustomInteger")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomInteger(@QueryParam("value") Long value) {
    boolean pass = false;
    String msg;
    Object test = customInteger.getValue();
    System.out.printf("+++ verifyInjectedCustomInteger, JsonNumber.class.CL: %s\n",
        JsonNumber.class.getClassLoader());
    System.out.printf("+++ customInteger.CL: %s\n",
        test.getClass().getClassLoader());
    Class[] ifaces = test.getClass().getInterfaces();
    for(Class iface : ifaces) {
        System.out.printf("%s: %s\n", iface, iface.getClassLoader());
    }
    JsonNumber customValue = JsonNumber.class.cast(test);
    if(customValue == null || customValue.isIntegral() == false) {
        msg = "customInteger value is null or not integral, FAIL";
    }
    else if(customValue.longValueExact() == value) {
        msg = "customInteger PASS";
        pass = true;
    }
    else {
        msg = String.format("customInteger: %d != %d", customValue, value);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
 
Example 4
Source File: RequestCaseJson.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns the DataValue represented by the given number object.
 */
private static DataValue<?> asIntegerValue( RequestCaseContext context, JsonNumber json, String format)
  {
  return
    "int64".equals( format)
    ? new LongValue( json.longValueExact())
    : new IntegerValue( json.intValueExact());
  }