com.google.gson.JsonElement.getAsBigDecimal()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(234)

本文整理了Java中com.google.gson.JsonElement.getAsBigDecimal()方法的一些代码示例,展示了JsonElement.getAsBigDecimal()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsBigDecimal()方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsBigDecimal

JsonElement.getAsBigDecimal介绍

[英]convenience method to get this element as a BigDecimal.
[中]以BigDecimal形式获取此元素的方便方法。

代码示例

代码示例来源:origin: searchbox-io/Jest

return (T) id.getAsBigDecimal();

代码示例来源:origin: json-path/JsonPath

@Test
public void bigdecimals_are_unwrapped() {
  final BigDecimal bd = BigDecimal.valueOf(Long.MAX_VALUE).add(BigDecimal.valueOf(10.5));
  final String json = "{bd-property = " + bd.toString() + "}";
  JsonElement node =  using(GSON_CONFIGURATION).parse(json).read("$.bd-property");
  BigDecimal val =  using(GSON_CONFIGURATION).parse(json).read("$.bd-property", BigDecimal.class);
  assertThat(val).isEqualTo(bd);
  assertThat(val).isEqualTo(node.getAsBigDecimal());
}

代码示例来源:origin: json-path/JsonPath

@Test
public void small_bigdecimals_are_unwrapped() {
  final BigDecimal bd = BigDecimal.valueOf(10.5);
  final String json = "{bd-property = " + bd.toString() + "}";
  JsonElement node =  using(GSON_CONFIGURATION).parse(json).read("$.bd-property");
  BigDecimal val =  using(GSON_CONFIGURATION).parse(json).read("$.bd-property", BigDecimal.class);
  assertThat(val).isEqualTo(bd);
  assertThat(val).isEqualTo(node.getAsBigDecimal());
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
 *
 * @return get this element as a {@link BigDecimal} if it is single element array.
 * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
 * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
 * @throws IllegalStateException if the array has more than one element.
 * @since 1.2
 */
@Override
public BigDecimal getAsBigDecimal() {
 if (elements.size() == 1) {
  return elements.get(0).getAsBigDecimal();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: lukas-krecan/JsonUnit

public BigDecimal decimalValue() {
  return jsonNode.getAsBigDecimal();
}

代码示例来源:origin: net.javacrumbs.json-unit/json-unit-core

public BigDecimal decimalValue() {
  return jsonNode.getAsBigDecimal();
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
 *
 * @return get this element as a {@link BigDecimal} if it is single element array.
 * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
 * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
 * @throws IllegalStateException if the array has more than one element.
 * @since 1.2
 */
@Override
public BigDecimal getAsBigDecimal() {
 if (elements.size() == 1) {
  return elements.get(0).getAsBigDecimal();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: eatnumber1/google-gson

/**
 * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
 *
 * @return get this element as a {@link BigDecimal} if it is single element array.
 * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
 * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
 * @throws IllegalStateException if the array has more than one element.
 * @since 1.2
 */
@Override
public BigDecimal getAsBigDecimal() {
 if (elements.size() == 1) {
  return elements.get(0).getAsBigDecimal();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: Nextdoor/bender

/**
 * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
 *
 * @return get this element as a {@link BigDecimal} if it is single element array.
 * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
 * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
 * @throws IllegalStateException if the array has more than one element.
 * @since 1.2
 */
@Override
public BigDecimal getAsBigDecimal() {
 if (elements.size() == 1) {
  return elements.get(0).getAsBigDecimal();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: Odoo-mobile/framework

/**
 * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
 *
 * @return get this element as a {@link BigDecimal} if it is single element array.
 * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
 * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
 * @throws IllegalStateException if the array has more than one element.
 * @since 1.2
 */
@Override
public BigDecimal getAsBigDecimal() {
 if (elements.size() == 1) {
  return elements.get(0).getAsBigDecimal();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: com.google/gson

/**
 * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
 *
 * @return get this element as a {@link BigDecimal} if it is single element array.
 * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
 * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
 * @throws IllegalStateException if the array has more than one element.
 * @since 1.2
 */
@Override
public BigDecimal getAsBigDecimal() {
 if (elements.size() == 1) {
  return elements.get(0).getAsBigDecimal();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.gson

/**
 * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
 *
 * @return get this element as a {@link BigDecimal} if it is single element array.
 * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
 * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
 * @throws IllegalStateException if the array has more than one element.
 * @since 1.2
 */
@Override
public BigDecimal getAsBigDecimal() {
 if (elements.size() == 1) {
  return elements.get(0).getAsBigDecimal();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: fesch/CanZE

/**
 * convenience method to get this array as a {@link BigDecimal} if it contains a single element.
 *
 * @return get this element as a {@link BigDecimal} if it is single element array.
 * @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive}.
 * @throws NumberFormatException if the element at index 0 is not a valid {@link BigDecimal}.
 * @throws IllegalStateException if the array has more than one element.
 * @since 1.2
 */
@Override
public BigDecimal getAsBigDecimal() {
 if (elements.size() == 1) {
  return elements.get(0).getAsBigDecimal();
 }
 throw new IllegalStateException();
}

代码示例来源:origin: javers/javers

@Override
public CommitId fromJson(JsonElement json, JsonDeserializationContext jsonDeserializationContext) {
  BigDecimal majorDotMinor = json.getAsBigDecimal();
  return CommitId.valueOf(majorDotMinor);
}

代码示例来源:origin: de.unijena.bioinf.ms/io

@Override
public boolean isInteger(JsonElement document) {
  if (!document.isJsonPrimitive()) return false;
  final JsonPrimitive primitive = (JsonPrimitive)document;
  if (!primitive.isNumber()) return false;
  final BigDecimal dec = document.getAsBigDecimal();
  if (dec.scale() > 0) return false;
  final BigInteger i = dec.toBigInteger();
  return i.bitLength() <= 31;
}

代码示例来源:origin: yggdrash/yggdrash

private BigDecimal getBalance(String key) {
  JsonObject storeValue = store.get(key);
  if (storeValue != null && storeValue.has("balance")) {
    return storeValue.get("balance").getAsBigDecimal();
  } else {
    return BigDecimal.ZERO;
  }
}

代码示例来源:origin: prowide/prowide-core

@Override
public XMLGregorianCalendar deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
  try {
    JsonObject obj  = jsonElement.getAsJsonObject();
    XMLGregorianCalendar xmlGregCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(
        obj.get(YEAR).getAsInt(),
        obj.get(MONTH).getAsInt(),
        obj.get(DAY).getAsInt(),
        obj.get(HOUR).getAsInt(),
        obj.get(MINUTE).getAsInt(),
        obj.get(SECOND).getAsInt(),
        0,
        obj.get(TIMEZONE).getAsInt());
    xmlGregCalendar.setFractionalSecond(obj.get(FRACTIONAL).getAsBigDecimal());
    return xmlGregCalendar;
    // use the line below as implementation in Java 8
    //return DatatypeFactory.newInstance().newXMLGregorianCalendar(jsonElement.getAsString());
  } catch (Exception e) {
    e.printStackTrace();
    return null;
  }
}

代码示例来源:origin: asakusafw/asakusafw

@Override
public void decimalProperty(PropertyName name, JsonObject context) throws IOException {
  JsonElement prop = property(context, name);
  if (prop == null) {
    return;
  }
  builder.add(name, prop.getAsBigDecimal());
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

protected Object readSimpleProperty(JsonElement valueElement, Datatype propertyType) {
  String value = valueElement.getAsString();
  if (value == null) return null;
  try {
    Class javaClass = propertyType.getJavaClass();
    if (BigDecimal.class.isAssignableFrom(javaClass)) {
      return valueElement.getAsBigDecimal();
    } else if (Long.class.isAssignableFrom(javaClass)) {
      return valueElement.getAsLong();
    } else if (Integer.class.isAssignableFrom(javaClass)) {
      return valueElement.getAsInt();
    } else if (Double.class.isAssignableFrom(javaClass)) {
      return valueElement.getAsDouble();
    }
    return propertyType.parse(value);
  } catch (ParseException e) {
    throw new EntitySerializationException(String.format("An error occurred while parsing property. Type [%s]. Value [%s].", propertyType, value), e);
  }
}

代码示例来源:origin: eatnumber1/google-gson

public BigDecimal deserialize(JsonElement json, Type typeOfT,
  JsonDeserializationContext context) throws JsonParseException {
 try {
  return json.getAsBigDecimal();
 } catch (NumberFormatException e) {
  throw new JsonSyntaxException(e);
 } catch (UnsupportedOperationException e) {
  throw new JsonSyntaxException(e);
 } catch (IllegalStateException e) {
  throw new JsonSyntaxException(e);
 }
}

相关文章