Code example for JsonPrimitive

Methods: getAsStringisBooleanisString

0
	    else if(json.isJsonPrimitive()) return handlePrimitive(json.getAsJsonPrimitive());
	    else if(json.isJsonArray()) return handleArray(json.getAsJsonArray(), context);
	    else return handleObject(json.getAsJsonObject(), context);
	  } 
	  private Object handlePrimitive(JsonPrimitive json) {
	    if(json.isBoolean())
	      return json.getAsBoolean();
	    else if(json.isString())
	      return json.getAsString();
	    else { 
	      BigDecimal bigDec = json.getAsBigDecimal();
	      // Find out if it is an int type 
	      try { 
	        bigDec.toBigIntegerExact();
	        try { return bigDec.intValueExact(); }
	        catch(ArithmeticException e) {}
	        return bigDec.longValue();
	      } catch(ArithmeticException e) {}
	      // Just return it as a double 
	      return bigDec.doubleValue();
Experience pair programming with AI  Get Codota for Java