All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dslplatform.json.parsers.JsDecimalParser Maven / Gradle / Ivy

package com.dslplatform.json.parsers;

import com.dslplatform.json.JsonReader;
import com.dslplatform.json.MyNumberConverter;
import jsonvalues.JsBigDec;
import jsonvalues.spec.Error;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Optional;
import java.util.function.Function;


final class JsDecimalParser extends AbstractParser {

    @Override
    JsBigDec value(final JsonReader reader) throws JsParserException {
        try {
            return JsBigDec.of(MyNumberConverter.parseDecimal(reader));
        } catch (IOException e) {
            throw new JsParserException(e.getMessage());
        }
    }

    JsBigDec valueSuchThat(final JsonReader reader,
                           final Function> fn
                          ) throws JsParserException {
        try {
            final BigDecimal      value  = MyNumberConverter.parseDecimal(reader);
            final Optional result = fn.apply(value);
            if (!result.isPresent()) return JsBigDec.of(value);
            throw reader.newParseError(result.toString());
        } catch (IOException e) {
            throw new JsParserException(e.getMessage());

        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy