Java BigDecimal Create getBigDecimal(JsonObject object, String memberName)

Here you can find the source of getBigDecimal(JsonObject object, String memberName)

Description

Gets nullable BigDecimal from a JSON object.

License

Open Source License

Parameter

Parameter Description
object json object
memberName member's name

Return

value

Declaration

public static BigDecimal getBigDecimal(JsonObject object, String memberName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

import java.math.BigDecimal;

public class Main {
    /**//from w  w w.java2  s .c o  m
     * Gets nullable BigDecimal from a JSON object.
     *
     * @param object json object
     * @param memberName member's name
     * @return {@link java.math.BigDecimal} value
     */
    public static BigDecimal getBigDecimal(JsonObject object, String memberName) {
        JsonPrimitive primitive = getPrimitiveChecked(object, memberName);
        return primitive == null ? null : primitive.getAsBigDecimal();
    }

    private static JsonPrimitive getPrimitiveChecked(JsonObject object, String memberName) {
        checkParameters(object, memberName);
        return object.getAsJsonPrimitive(memberName);
    }

    private static void checkParameters(JsonObject object, String memberName) {
        checkObject(object);
        checkMemberName(memberName);
    }

    private static void checkObject(JsonObject object) {
        if (object == null) {
            throw new NullPointerException("JSON object is null.");
        }
    }

    private static void checkMemberName(String memberName) {
        if (memberName == null) {
            throw new NullPointerException("Member name is null.");
        }
        if (memberName.length() == 0) {
            throw new IllegalArgumentException("Member is an empty string.");
        }
    }
}

Related

  1. createBigDecimal(String val)
  2. getBdIgnoreNull(BigDecimal bigDecimalPara)
  3. getBigDecimal(BigDecimal bigDecimal)
  4. getBigDecimal(double value, int decimals)
  5. getBigDecimal(final String str, final int scale)
  6. getBigDecimal(Map map, String attr)
  7. getBigDecimal(Number number)
  8. getBigDecimal(Object number)
  9. getBigDecimal(Object o)