How to handle Integer in Rest assured response when the config is set to BigDecimal

57 views Asked by At

I want to configure the rest assured response such that I can get the response in Big Decimal only. If the number is Integer, I would like to convert it to BigDecimal as well. Is there a way I can do that?

I know that I can set set the config to BigDecimal which will convert all decimal numbers to BigDecimal but obviously it wont convert the non decimal numbers. Is there a way I can achieve that decimal numbers are converted to BigDecimal and non decimal are converted to BigInteger from Rest assured config? And then I can convert the BigInteger to BigDecimal?

Currently I am doping the below steps

 RestAssured.config = RestAssured.config().jsonConfig(jsonConfig().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL));

And then I am writing a method as below to handle the integers

public BigDecimal readJsonPathValueAsBigDecimal(Object obj){
    if (obj instanceof Integer)
    {
        return new BigDecimal((Integer) obj);
    }
    return (BigDecimal) obj;
}

Any other better approach/suggestions are also welcome

0

There are 0 answers