Here you can find the source of jsonNumberToBigDecimal(final JsonNumber n, final int defaultValue)
public static BigDecimal jsonNumberToBigDecimal(final JsonNumber n, final int defaultValue)
//package com.java2s; /**/* ww w . ja v a 2s . c o m*/ * This file is part of the Aerodrome package, and is subject to the * terms and conditions defined in file 'LICENSE', which is part * of this source code package. * * Copyright (c) 2016 All Rights Reserved, John T. Quinn III, * <johnquinn3@gmail.com> * * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A * PARTICULAR PURPOSE. */ import java.math.BigDecimal; import javax.json.JsonNumber; import javax.json.JsonObject; public class Main { public static BigDecimal jsonNumberToBigDecimal(final JsonNumber n, final int defaultValue) { if (n == null) return new BigDecimal(defaultValue); return n.bigDecimalValue(); } public static BigDecimal jsonNumberToBigDecimal(final JsonObject json, final String property, final int defaultValue) { if (json == null || property == null || property.isEmpty()) return new BigDecimal(defaultValue); try { return jsonNumberToBigDecimal(json.getJsonNumber(property), defaultValue); } catch (Exception e) { return new BigDecimal(defaultValue); } } public static BigDecimal getJsonNumber(final JsonNumber n) { final BigDecimal b = new BigDecimal(0); if (n == null) return b; return n.bigDecimalValue(); } public static BigDecimal getJsonNumber(final JsonObject obj, final String property) { try { return obj.getJsonNumber(property).bigDecimalValue(); } catch (ClassCastException e) { return new BigDecimal(0); } } }