Java 类javax.json.JsonNumber 实例源码

项目:microprofile-jwt-auth    文件:ProviderInjectionEndpoint.java   
@GET
@Path("/verifyInjectedCustomDouble")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomDouble(@QueryParam("value") Double value) {
    boolean pass = false;
    String msg;
    // iat
    JsonNumber customValue = customDouble.get();
    if(customValue == null) {
        msg = "customDouble value is null, FAIL";
    }
    else if(Math.abs(customValue.doubleValue() - value.doubleValue()) < 0.00001) {
        msg = "customDouble PASS";
        pass = true;
    }
    else {
        msg = String.format("customDouble: %s != %.8f", customValue, value);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionEndpoint.java   
@GET
@Path("/verifyInjectedCustomDouble")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomDouble(@QueryParam("value") Double value) {
    boolean pass = false;
    String msg;
    // iat
    JsonNumber customValue = customDouble.getValue();
    if(customValue == null) {
        msg = "customDouble value is null, FAIL";
    }
    else if(Math.abs(customValue.doubleValue() - value.doubleValue()) < 0.00001) {
        msg = "customDouble PASS";
        pass = true;
    }
    else {
        msg = String.format("customDouble: %s != %.8f", customValue, value);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:devtools-driver    文件:JavaxJson.java   
/**
 * Converts a {@link JsonValue} to its corresponding Java object. Values of type {@link
 * JsonObject} or {@link JsonArray} are converted as specified by {@link #toJavaMap} and {@link
 * #toJavaList}, respectively.
 */
@Nullable
public static Object toJavaObject(JsonValue value) {
  switch (value.getValueType()) {
    case ARRAY:
      return toJavaList((JsonArray) value);
    case FALSE:
      return Boolean.FALSE;
    case NULL:
      return null;
    case NUMBER:
      JsonNumber number = (JsonNumber) value;
      return number.isIntegral() ? number.intValue() : number.doubleValue();
    case OBJECT:
      return toJavaMap((JsonObject) value);
    case STRING:
      return ((JsonString) value).getString();
    case TRUE:
      return Boolean.TRUE;
    default:
      throw new VerifyException("Json value with unknown type: " + value);
  }
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:JsonUtil.java   
public static Object unbox(JsonValue value, Function<JsonStructure, Object> convert) throws JsonException {
    switch (value.getValueType()) {
        case ARRAY:
        case OBJECT:
            return convert.apply((JsonStructure) value);
        case FALSE:
            return Boolean.FALSE;
        case TRUE:
            return Boolean.TRUE;
        case NULL:
            return null;
        case NUMBER:
            JsonNumber number = (JsonNumber) value;
            return number.isIntegral() ? number.longValue() : number.doubleValue();
        case STRING:
            return ((JsonString) value).getString();
        default:
            throw new JsonException("Unknow value type");
    }
}
项目:cookjson    文件:NumberTest.java   
@Test
public void testInt ()
{
    JsonNumber v = new CookJsonInt (1234);

    Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

    Assert.assertEquals (true, v.isIntegral ());
    Assert.assertEquals (1234, v.intValue ());
    Assert.assertEquals (1234, v.intValueExact ());
    Assert.assertEquals (1234, v.longValue ());
    Assert.assertEquals (1234, v.longValueExact ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValue ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValueExact ());
    Assert.assertEquals (new BigDecimal (1234), v.bigDecimalValue ());
    Assert.assertEquals (1234, v.doubleValue (), 0);
    Assert.assertEquals (new BigDecimal (1234).hashCode (), v.hashCode ());
    Assert.assertEquals ("1234", v.toString ());
}
项目:microprofile-conference    文件:SessionRating.java   
public static SessionRating fromJSON(JsonObject sessionRatingJson) {
    String id = getStringFromJson("id", sessionRatingJson);
    String session = getStringFromJson("session", sessionRatingJson);
    String attendeeId = getStringFromJson("attendeeId", sessionRatingJson);
    String _rev = getStringFromJson("_rev", sessionRatingJson);
    String _id = getStringFromJson("_id", sessionRatingJson);
    int rating = 0;
    if (sessionRatingJson.containsKey("rating")) {
        JsonNumber ratingJson = sessionRatingJson.getJsonNumber("rating");
        if (ratingJson != null) {
            rating = ratingJson.intValue();
        }
    }

    SessionRating sessionRating = new SessionRating(id, session, attendeeId, rating, _id, _rev);
    return sessionRating;
}
项目:cookjson    文件:NumberTest.java   
@Test
public void testDouble ()
{
    double d = 1234;
    JsonNumber v = new CookJsonDouble (d);

    Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

    Assert.assertEquals (false, v.isIntegral ());
    Assert.assertEquals (1234, v.intValue ());
    Assert.assertEquals (1234, v.intValueExact ());
    Assert.assertEquals (1234, v.longValue ());
    Assert.assertEquals (1234, v.longValueExact ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValue ());
    Assert.assertEquals (new BigInteger ("1234"), v.bigIntegerValueExact ());
    Assert.assertEquals (BigDecimal.valueOf (d), v.bigDecimalValue ());
    Assert.assertEquals (d, v.doubleValue (), 0);
    Assert.assertEquals (BigDecimal.valueOf (d).hashCode (), v.hashCode ());
    Assert.assertEquals (DoubleUtils.toString (d), v.toString ());
}
项目:cookjson    文件:NumberTest.java   
@Test
public void testBigInteger ()
{
    BigInteger d = new BigInteger ("1234");
    JsonNumber v = new CookJsonBigDecimal (d);

    Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

    Assert.assertEquals (true, v.isIntegral ());
    Assert.assertEquals (d.intValue (), v.intValue ());
    Assert.assertEquals (d.intValue (), v.intValueExact ());
    Assert.assertEquals (d.longValue (), v.longValue ());
    Assert.assertEquals (d.longValue (), v.longValueExact ());
    Assert.assertEquals (d, v.bigIntegerValue ());
    Assert.assertEquals (d, v.bigIntegerValueExact ());
    Assert.assertEquals (new BigDecimal (d), v.bigDecimalValue ());
    Assert.assertEquals (d.doubleValue (), v.doubleValue (), 0);
    Assert.assertEquals (new BigDecimal (d).hashCode (), v.hashCode ());
    Assert.assertEquals (d.toString (), v.toString ());
}
项目:java-translatebot    文件:OauthHandler.java   
private Object plainifyJsonValue(final JsonValue jval) {
    switch (jval.getValueType()) {
    case ARRAY:
        return plainifyJsonArray((JsonArray) jval);
    case FALSE:
        return Boolean.FALSE;
    case TRUE:
        return Boolean.TRUE;
    case NULL:
        return null;
    case NUMBER:
        return ((JsonNumber) jval).bigDecimalValue();
    case OBJECT:
        return plainifyJsonObject((JsonObject) jval);
    case STRING:
        return ((JsonString) jval).getString();
    default:
        throw new RuntimeException("unexpected json type");
    }
}
项目:opendata-common    文件:JsonUtils.java   
public static Boolean getBoolean( JsonObject o, String n, Boolean defaultValue )
{
    JsonValue v = o.get( n );
    if( v == null ) {
        return defaultValue;
    }
    switch( v.getValueType() ) {
        case NUMBER:
            JsonNumber jn = (JsonNumber) v;
            return !jn.bigIntegerValue().
                    equals( BigInteger.ZERO );
        case STRING:
            JsonString s = (JsonString) v;
            return Boolean.parseBoolean( s.getString() );
        case TRUE:
            return true;
        case FALSE:
            return false;
        case NULL:
            return defaultValue;
        default:
            return Boolean.parseBoolean( v.toString() );
    }
}
项目:hibiscus    文件:ArrayValidationTest.java   
@Test
public void manyDuplications() {
    String json = "[123, 456, 456, 123]";
    Schema schema = schema(array(integer()).unique());
    JsonValidator validator = new BasicJsonValidator(schema);
    ValidationResult result = validator.validate(new StringReader(json));

    assertResultValid(result, json);
    assertThat(result.getProblems().size(), equalTo(2));

    assertThat(result.getProblems().get(0), instanceOf(ArrayDuplicateItemProblem.class));
    ArrayDuplicateItemProblem p0 = (ArrayDuplicateItemProblem)result.getProblems().get(0);
    assertThat(p0.getPointer().toString(), equalTo(""));
    assertThat(p0.getDuplicateIndex(), equalTo(2));
    assertThat(((JsonNumber)p0.getDuplicateItem()).intValue(), equalTo(456));
    assertNotNull(p0.getDescription());

    assertThat(result.getProblems().get(1), instanceOf(ArrayDuplicateItemProblem.class));
    ArrayDuplicateItemProblem p1 = (ArrayDuplicateItemProblem)result.getProblems().get(1);
    assertThat(p1.getPointer().toString(), equalTo(""));
    assertThat(p1.getDuplicateIndex(), equalTo(3));
    assertThat(((JsonNumber)p1.getDuplicateItem()).intValue(), equalTo(123));
    assertNotNull(p1.getDescription());
}
项目:hibiscus    文件:NumberValidationTest.java   
@Test
public void notExistInNone() {
    String json = "[12.34]";
    Schema schema = schema(array(number().enumeration()));
    JsonValidator validator = new BasicJsonValidator(schema);
    ValidationResult result = validator.validate(new StringReader(json));

    assertResultValid(result, json);
    assertEquals(1, result.getProblems().size());
    assertTrue(result.getProblems().get(0) instanceof NoSuchEnumeratorProblem);
    NoSuchEnumeratorProblem p = (NoSuchEnumeratorProblem)result.getProblems().get(0);
    assertEquals(new BigDecimal("12.34"), ((JsonNumber)p.getCauseValue()).bigDecimalValue());
    Set<Object> expected = p.getEnumerators();
    assertEquals(0, expected.size());
    assertNotNull(p.getDescription());
}
项目:opendata-common    文件:JsonUtils.java   
public static LocalTime getLocalTime( JsonObject o, String n )
{
    JsonValue v = o.get( n );
    if( v == null ) {
        return null;
    }
    switch( v.getValueType() ) {
        case STRING:
            return TimeUtils.getLocalTime( ((JsonString) v).getString() );

        case NUMBER:
            return TimeUtils.getLocalTime( ((JsonNumber) v).longValue() );
        default:
            return null;
    }
}
项目:hibiscus    文件:NumberValidationTest.java   
@Test
public void notExistInMany() {
    String json = "[3.14]";
    Schema schema = schema(array(number().enumeration(new BigDecimal("12.34"), new BigDecimal("56.78"))));
    JsonValidator validator = new BasicJsonValidator(schema);
    ValidationResult result = validator.validate(new StringReader(json));

    assertResultValid(result, json);
    assertEquals(1, result.getProblems().size());
    assertTrue(result.getProblems().get(0) instanceof NoSuchEnumeratorProblem);
    NoSuchEnumeratorProblem p = (NoSuchEnumeratorProblem)result.getProblems().get(0);
    assertEquals(new BigDecimal("3.14"), ((JsonNumber)p.getCauseValue()).bigDecimalValue());
    Set<Object> expected = p.getEnumerators();
    assertEquals(2, expected.size());
    assertNotNull(p.getDescription());
}
项目:hibiscus    文件:IntegerValidationTest.java   
@Test
public void notExistInNone() {
    String json = "[1]";
    Schema schema = schema(array(integer().enumeration()));
    JsonValidator validator = new BasicJsonValidator(schema);
    ValidationResult result = validator.validate(new StringReader(json));

    assertResultValid(result, json);
    assertEquals(1, result.getProblems().size());
    assertTrue(result.getProblems().get(0) instanceof NoSuchEnumeratorProblem);
    NoSuchEnumeratorProblem p = (NoSuchEnumeratorProblem)result.getProblems().get(0);
    assertEquals(1, ((JsonNumber)p.getCauseValue()).intValue());
    Set<Object> expected = p.getEnumerators();
    assertEquals(0, expected.size());
    assertNotNull(p.getDescription());
}
项目:hibiscus    文件:IntegerValidationTest.java   
@Test
public void notExistInOne() {
    String json = "[12]";
    Schema schema = schema(array(integer().enumeration(123)));
    JsonValidator validator = new BasicJsonValidator(schema);
    ValidationResult result = validator.validate(new StringReader(json));

    assertResultValid(result, json);
    assertEquals(1, result.getProblems().size());
    assertTrue(result.getProblems().get(0) instanceof NoSuchEnumeratorProblem);
    NoSuchEnumeratorProblem p = (NoSuchEnumeratorProblem)result.getProblems().get(0);
    assertEquals(12, ((JsonNumber)p.getCauseValue()).intValue());
    Set<Object> expected = p.getEnumerators();
    assertEquals(1, expected.size());
    assertNotNull(p.getDescription());
}
项目:hibiscus    文件:IntegerValidationTest.java   
@Test
public void notExistInMany() {
    String json = "[42]";
    Schema schema = schema(array(integer().enumeration(1, 12, 123)));
    JsonValidator validator = new BasicJsonValidator(schema);
    ValidationResult result = validator.validate(new StringReader(json));

    assertResultValid(result, json);
    assertEquals(1, result.getProblems().size());
    assertTrue(result.getProblems().get(0) instanceof NoSuchEnumeratorProblem);
    NoSuchEnumeratorProblem p = (NoSuchEnumeratorProblem)result.getProblems().get(0);
    assertEquals(42, ((JsonNumber)p.getCauseValue()).intValue());
    Set<Object> expected = p.getEnumerators();
    assertEquals(3, expected.size());
    assertNotNull(p.getDescription());
}
项目:cookjson    文件:NumberTest.java   
@Test
    public void testBigDecimal ()
    {
        BigDecimal d = new BigDecimal ("1234.1234");
        JsonNumber v = new CookJsonBigDecimal (d);

        Assert.assertEquals (ValueType.NUMBER, v.getValueType ());

        Assert.assertEquals (false, v.isIntegral ());
        Assert.assertEquals (d.intValue (), v.intValue ());
//      Assert.assertEquals (d.intValue (), v.intValueExact ());
        Assert.assertEquals (d.longValue (), v.longValue ());
//      Assert.assertEquals (d.longValue (), v.longValueExact ());
        Assert.assertEquals (d.toBigInteger (), v.bigIntegerValue ());
//      Assert.assertEquals (d.toBigInteger (), v.bigIntegerValueExact ());
        Assert.assertEquals (d, v.bigDecimalValue ());
        Assert.assertEquals (d.doubleValue (), v.doubleValue (), 0);
        Assert.assertEquals (d.hashCode (), v.hashCode ());
        Assert.assertEquals (d.toString (), v.toString ());
    }
项目:opendata-common    文件:MapConfiguration.java   
private Object map( JsonValue v )
{
    switch( v.getValueType() ) {
        case STRING:
            return ((JsonString) v).getString();

        case NUMBER:
            return ((JsonNumber) v).bigDecimalValue();

        case TRUE:
            return true;

        case FALSE:
            return false;

        case OBJECT:
            return MapBuilder.fromJsonObject( (JsonObject) v );

        case ARRAY:
            return CollectionBuilder.fromJsonArray( (JsonArray) v );

        case NULL:
        default:
            return null;
    }
}
项目:opendata-common    文件:JsonUtils.java   
public static Time getTime( JsonValue v )
{
    if( v == null ) {
        return null;
    }
    switch( v.getValueType() ) {
        case NUMBER:
            return new Time( ((JsonNumber) v).longValue() );
        case STRING:
            return Time.valueOf( ((JsonString) v).getString() );
        case TRUE:
        case FALSE:
        case NULL:
            return null;
        default:
            return Time.valueOf( v.toString() );
    }
}
项目:microprofile-jwt-auth    文件:ProviderInjectionEndpoint.java   
@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;
}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionEndpoint.java   
@GET
@Path("/verifyInjectedCustomInteger")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomInteger(@QueryParam("value") Long value) {
    boolean pass = false;
    String msg;
    // iat
    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;
}
项目:javametrics    文件:Metrics.java   
@Override
public void processData(List<String> jsaonData) {
    for (Iterator<String> iterator = jsaonData.iterator(); iterator.hasNext();) {
        String jsonStr = iterator.next();
        JsonReader jsonReader = Json.createReader(new StringReader(jsonStr));
        try {
            JsonObject jsonObject = jsonReader.readObject();
            String topicName = jsonObject.getString("topic", null);
            switch (topicName) {
            case "http":
                handleHttpTopic(jsonObject.getJsonObject("payload"));
                break;
            case "cpu":
                JsonNumber system = jsonObject.getJsonObject("payload").getJsonNumber("system");
                JsonNumber process = jsonObject.getJsonObject("payload").getJsonNumber("process");

                os_cpu_used_ratio.set(Double.valueOf(system.doubleValue()));
                process_cpu_used_ratio.set(Double.valueOf(process.doubleValue()));
                break;
            default:
                break;
            }
        } catch (JsonException je) {
            // Skip this object, log the exception and keep trying with
            // the rest of the list
            // System.err.println("Error in json: \n" + jsonStr);
            // je.printStackTrace();
        }
    }
}
项目:oauth-filter-for-java    文件:JsonUtils.java   
static long getLong(JsonObject jsonObject, String name)
{
    return Optional.ofNullable(jsonObject.get(name))
            .filter(it -> it.getValueType() == JsonValue.ValueType.NUMBER)
            .map(it -> ((JsonNumber) it).longValue())
            .orElse(Long.MIN_VALUE);
}
项目:aceql-http    文件:ResultAnalyzer.java   
/**
    * Returns the int value for a name
    * @param name
    * @return the value
    */
   public int getIntvalue(String name) {
if (name == null) {
    throw new NullPointerException("name is null!");
}

if (isInvalidJsonStream()) {
    return -1;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonNumber value = (JsonNumber) object.get(name);

    if (value == null) {
        return -1;
    }

    return value.intValue();
} catch (Exception e) {
    this.parseException = e;
    return -1;
}
   }
项目:aceql-http    文件:ResultAnalyzer.java   
/**
    * Returns the error_type in case of failure
    * @return the error_type in case of failure, -1 if no error
    */
   public int getErrorType() {

if (isInvalidJsonStream()) {
    return 0;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString status = (JsonString) object.get("status");

    if (status == null) {
        return -1;
    }

    JsonNumber errorType = (JsonNumber) object.get("error_type");

    if (errorType == null) {
        return -1;
    }
    else {
        return errorType.intValue();
    }
} catch (Exception e) {
    this.parseException = e;
    return -1;
}


   }
项目:javaee-calculator    文件:AdditionResource.java   
@POST
public void addition(@Suspended AsyncResponse response, JsonObject input) {
    response.setTimeout(500, TimeUnit.MILLISECONDS);
    response.setTimeoutHandler(this::handleTimeout);
    int a = ofNullable(input.getJsonNumber("a")).
            map(JsonNumber::intValue).
            orElseThrow(() -> new LackingParameterException("a"));
    int b = ofNullable(input.getJsonNumber("b")).
            map(JsonNumber::intValue).
            orElseThrow(() -> new LackingParameterException("b"));
    supplyAsync(() -> computeResult(a, b), mes).thenAccept(response::resume);
}
项目:devtools-driver    文件:WebInspectorHelper.java   
private ImmutableList<CallArgument> processScriptArguments(JsonArray args) {
  ImmutableList.Builder<CallArgument> argsBuilder = ImmutableList.builder();
  for (JsonValue arg : args) {
    if (ValueType.OBJECT.equals(arg.getValueType())) {
      JsonObject jsonArg = (JsonObject) arg;
      if (jsonArg.containsKey("ELEMENT")) {
        NodeId n = new NodeId(Integer.parseInt(jsonArg.getString("ELEMENT").split("_")[1]));
        RemoteWebElement rwep = new RemoteWebElement(n, this);
        argsBuilder.add(callArgument().withObjectId(rwep.getRemoteObject().getId()));
      } else {
        log.info("JsonObject without ELEMENT tag" + jsonArg);
      }
    } else if (ValueType.ARRAY.equals(arg.getValueType())) {
      JsonObject array = getScriptResponse("return " + arg + ";");
      argsBuilder.add(callArgument().withObjectId(getResponseBody(array).getString("objectId")));
    } else if (ValueType.FALSE.equals(arg.getValueType())) {
      argsBuilder.add(callArgument().withValue(false));
    } else if (ValueType.TRUE.equals(arg.getValueType())) {
      argsBuilder.add(callArgument().withValue(true));
    } else if (ValueType.NUMBER.equals(arg.getValueType())) {
      argsBuilder.add(callArgument().withValue(((JsonNumber) arg).longValue()));
    } else if (ValueType.STRING.equals(arg.getValueType())) {
      argsBuilder.add(callArgument().withValue(((JsonString) arg).getString()));
    } else {
      throw new WebDriverException("Unsupported argument type: " + arg.getValueType());
    }
  }
  return argsBuilder.build();
}
项目:devtools-driver    文件:SetFrameHandler.java   
@Override
public Response handle() throws Exception {
  JsonValue p = getRequest().getPayload().get("id");

  if (JsonValue.NULL.equals(p)) {
    getWebDriver().getContext().setCurrentFrame(null, null, null);
  } else {
    RemoteWebElement iframe;
    switch (p.getValueType()) {
      case NUMBER:
        iframe = getIframe(((JsonNumber) p).intValue());
        break;
      case OBJECT:
        String id = ((JsonObject) p).getString("ELEMENT");
        iframe = getWebDriver().createElement(id);
        break;
      case STRING:
        iframe = getIframe(((JsonString) p).getString());
        break;
      default:
        throw new UnsupportedCommandException("cannot select frame by " + p.getClass());
    }
    RemoteWebElement document = iframe.getContentDocument();
    RemoteWebElement window = iframe.getContentWindow();
    getWebDriver().getContext().setCurrentFrame(iframe, document, window);
  }

  Response res = new Response();
  res.setSessionId(getSession().getSessionId());
  res.setStatus(0);
  res.setValue(new JSONObject());
  return res;
}
项目:sample-acmegifts    文件:Occasion.java   
public Contribution(JsonObject json) {
  String method = "Contribution";
  logger.entering(clazz, method, json);

  setUserId(json.getString(OCCASION_CONTRIBUTION_USER_ID_KEY, null));

  JsonNumber amount = json.getJsonNumber(OCCASION_CONTRIBUTION_AMOUNT_KEY);
  setAmount((amount == null) ? 0 : amount.doubleValue());

  logger.exiting(clazz, method, "amount: " + getAmount() + ", userId: " + getUserId());
}
项目:bluemix-liberty-microprofile-demo    文件:JsonUtil.java   
public static Duration getDuration(String key, JsonObject json) {
    Duration result = null;
    if (json.containsKey(key)) {
        JsonNumber value = json.getJsonNumber(key);
        if (value != null) {
            result = duration(value.intValueExact());
        }
    }
    return result;
}
项目:Peking-University-Open-Research-Data-Platform    文件:Dataverses.java   
@POST
@Path("{identifier}/metadatablocks")
@Produces(MediaType.APPLICATION_JSON)
public Response setMetadataBlocks( @PathParam("identifier")String dvIdtf, @QueryParam("key") String apiKey, String blockIds ) {

    List<MetadataBlock> blocks = new LinkedList<>();
    try {
        for ( JsonValue blockId : Util.asJsonArray(blockIds).getValuesAs(JsonValue.class) ) {
            MetadataBlock blk = (blockId.getValueType()==ValueType.NUMBER)
                                    ? findMetadataBlock( ((JsonNumber)blockId).longValue() )
                                    : findMetadataBlock( ((JsonString)blockId).getString() );
            if ( blk == null ) {
                return errorResponse(Response.Status.BAD_REQUEST, "Can't find metadata block '"+ blockId + "'");
            }
            blocks.add( blk );
        }
    } catch( Exception e ) {
        return errorResponse(Response.Status.BAD_REQUEST, e.getMessage());
    }

    try {
        User u = findUserOrDie(apiKey);
        Dataverse dataverse = findDataverseOrDie(dvIdtf);
        execCommand( new UpdateDataverseMetadataBlocksCommand.SetBlocks(u, dataverse, blocks),
                "updating metadata blocks for dataverse " + dvIdtf );
        return okResponse("Metadata blocks of dataverse " + dvIdtf + " updated.");

    } catch (WrappedResponse ex) {
        return ex.getResponse();
    }
}
项目:ulogin_spring_security    文件:UloginAuthentifiactionProvider.java   
public ULoginUser.Sex getSex(JsonObject obj){
    JsonNumber sexNum = obj.getJsonNumber("sex");
    if(sexNum==null){
        return null;
    }
    int i = sexNum.intValue();
    if(i<0||i>3){
        return null;
    }
    return ULoginUser.Sex.values()[i];
}
项目:aws-iot-mqtt-load-generator    文件:Function.java   
public static Function newInstance(FunctionType type, String var, JsonArray params) {

        Properties props = new Properties();
        if (params != null) {

            Iterator<JsonValue> iter = params.iterator();
            while (iter.hasNext()) {
                JsonValue val = iter.next();
                JsonObject p = (JsonObject) val;
                Set<Entry<String, JsonValue>> keys = p.entrySet();

                for (Entry<String, JsonValue> ev : keys) {
                    switch (ev.getValue().getValueType()) {
                        case NUMBER:
                            props.setProperty(ev.getKey(), Integer.toString(((JsonNumber) ev.getValue()).intValue()));
                            break;
                        case STRING:
                            props.setProperty(ev.getKey(), ((JsonString) ev.getValue()).getString());
                            break;
                        default:
                            throw new RuntimeException("Unknown parameter type");
                    }
                }
            }
        }

        switch (type) {
            case SINE:
                return new SineFunction(type, var, props);
            case RANDOM:
                return new RandomFunction(type, var, props);
            case EXPR:
                return new ExpressionFunction(type, var, props);
            case TEXT:
                return new TextFunction(type, var, props);
            default:
                throw new RuntimeException("Unsupported function type: " + type.name());
        }
    }
项目:aerodrome-for-jet    文件:SkuAttributeRec.java   
public static SkuAttributeRec fromJson( final JsonObject json )
{
  if ( json == null )
    throw new IllegalArgumentException( "json can't be null" );

  final JsonNumber id = json.getJsonNumber( "attribute_id" );
  if ( id == null )
    throw new IllegalArgumentException( "object missing attribute_id property" );

  return new SkuAttributeRec( id.longValue(), json.getString( "attribute_value", "" ), json.getString( "attribute_value_units", "" ));
}
项目:aerodrome-for-jet    文件:Utils.java   
public static BigDecimal getJsonNumber( final JsonNumber n )
{
  final BigDecimal b = new BigDecimal( 0 );
  if ( n == null )
    return b;

  return n.bigDecimalValue();
}
项目:aerodrome-for-jet    文件:Utils.java   
public static BigDecimal jsonNumberToBigDecimal( final JsonNumber n, final int defaultValue )
{
  if ( n == null )
    return new BigDecimal( defaultValue );

  return n.bigDecimalValue();
}
项目:hibiscus    文件:MaxNumberFacet.java   
@Override
public void apply(JsonNumber value, List<Problem> problems) {
    BigDecimal decimal = value.bigDecimalValue();
    int result = decimal.compareTo(bound.getValue());
    if (bound.isExclusive()) {
        if (result >= 0) {
            problems.add(new ExclusiveUpperBoundProblem(bound));
        }
    } else {
        if (result > 0) {
            problems.add(new InclusiveUpperBoundProblem(bound));
        }
    }
}
项目:hibiscus    文件:WritableJsonDecimalNumber.java   
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof JsonNumber)) {
        return false;
    }
    JsonNumber other = (JsonNumber)obj;
    return value.equals(other.bigDecimalValue());
}
项目:hibiscus    文件:IntegerValidationTest.java   
@Test
public void failure() {
    String json = "[31]";
    JsonValidator validator = new BasicJsonValidator(schema);
    ValidationResult result = validator.validate(new StringReader(json));

    assertResultValid(result, json);
    assertEquals(1, result.getProblems().size());
    assertTrue(result.getProblems().get(0) instanceof AssertionFailureProblem);
    AssertionFailureProblem<?> p = (AssertionFailureProblem<?>)result.getProblems().get(0);
    assertEquals(31, ((JsonNumber)p.getCauseValue()).intValue());
    assertEquals("Value must be a even number.", p.getDescription());
}