當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonNumber類代碼示例

本文整理匯總了Java中javax.json.JsonNumber的典型用法代碼示例。如果您正苦於以下問題:Java JsonNumber類的具體用法?Java JsonNumber怎麽用?Java JsonNumber使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonNumber類屬於javax.json包,在下文中一共展示了JsonNumber類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyInjectedCustomDouble

import javax.json.JsonNumber; //導入依賴的package包/類
@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;
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:25,代碼來源:ProviderInjectionEndpoint.java

示例2: verifyInjectedCustomDouble

import javax.json.JsonNumber; //導入依賴的package包/類
@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;
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:25,代碼來源:ClaimValueInjectionEndpoint.java

示例3: toJavaObject

import javax.json.JsonNumber; //導入依賴的package包/類
/**
 * 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);
  }
}
 
開發者ID:google,項目名稱:devtools-driver,代碼行數:28,代碼來源:JavaxJson.java

示例4: unbox

import javax.json.JsonNumber; //導入依賴的package包/類
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");
    }
}
 
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:21,代碼來源:JsonUtil.java

示例5: testInt

import javax.json.JsonNumber; //導入依賴的package包/類
@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 ());
}
 
開發者ID:coconut2015,項目名稱:cookjson,代碼行數:20,代碼來源:NumberTest.java

示例6: fromJSON

import javax.json.JsonNumber; //導入依賴的package包/類
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;
}
 
開發者ID:eclipse,項目名稱:microprofile-conference,代碼行數:18,代碼來源:SessionRating.java

示例7: testDouble

import javax.json.JsonNumber; //導入依賴的package包/類
@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 ());
}
 
開發者ID:coconut2015,項目名稱:cookjson,代碼行數:21,代碼來源:NumberTest.java

示例8: testBigInteger

import javax.json.JsonNumber; //導入依賴的package包/類
@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 ());
}
 
開發者ID:coconut2015,項目名稱:cookjson,代碼行數:21,代碼來源:NumberTest.java

示例9: plainifyJsonValue

import javax.json.JsonNumber; //導入依賴的package包/類
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");
    }
}
 
開發者ID:aztecrex,項目名稱:java-translatebot,代碼行數:21,代碼來源:OauthHandler.java

示例10: getBoolean

import javax.json.JsonNumber; //導入依賴的package包/類
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() );
    }
}
 
開發者ID:peter-mount,項目名稱:opendata-common,代碼行數:25,代碼來源:JsonUtils.java

示例11: manyDuplications

import javax.json.JsonNumber; //導入依賴的package包/類
@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());
}
 
開發者ID:i49,項目名稱:hibiscus,代碼行數:25,代碼來源:ArrayValidationTest.java

示例12: notExistInNone

import javax.json.JsonNumber; //導入依賴的package包/類
@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());
}
 
開發者ID:i49,項目名稱:hibiscus,代碼行數:17,代碼來源:NumberValidationTest.java

示例13: getLocalTime

import javax.json.JsonNumber; //導入依賴的package包/類
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;
    }
}
 
開發者ID:peter-mount,項目名稱:opendata-common,代碼行數:17,代碼來源:JsonUtils.java

示例14: notExistInMany

import javax.json.JsonNumber; //導入依賴的package包/類
@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());
}
 
開發者ID:i49,項目名稱:hibiscus,代碼行數:17,代碼來源:NumberValidationTest.java

示例15: notExistInNone

import javax.json.JsonNumber; //導入依賴的package包/類
@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());
}
 
開發者ID:i49,項目名稱:hibiscus,代碼行數:17,代碼來源:IntegerValidationTest.java


注:本文中的javax.json.JsonNumber類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。