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

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

package com.dslplatform.json.parsers;

import com.dslplatform.json.JsonReader;
import com.dslplatform.json.ParsingException;
import jsonvalues.JsBool;
import jsonvalues.JsNull;
import jsonvalues.JsValue;

final class JsBoolParser extends AbstractParser {

    JsBool value(final JsonReader reader) throws JsParserException {
        try {
            if (reader.wasTrue()) return JsBool.TRUE;
            else if (reader.wasFalse()) return JsBool.FALSE;
            throw reader.newParseErrorAt("Found invalid boolean value",
                                         0
                                        );
        } catch (ParsingException e) {
            throw new JsParserException(e.getMessage());

        }
    }

    JsValue nullOrTrue(final JsonReader reader) throws JsParserException {
        try {
            return reader.wasNull() ? JsNull.NULL : True(reader);
        } catch (ParsingException e) {
            throw new JsParserException(e.getMessage());

        }
    }

    JsBool True(final JsonReader reader) throws JsParserException {
        try {
            if (reader.wasTrue()) return JsBool.TRUE;
            throw reader.newParseErrorAt("Found invalid boolean value. True was expected.",
                                         0
                                        );
        } catch (ParsingException e) {
            throw new JsParserException(e.getMessage());

        }
    }

    JsValue nullOrFalse(final JsonReader reader) throws JsParserException {
        try {
            return reader.wasNull() ? JsNull.NULL : False(reader);
        } catch (ParsingException e) {
            throw new JsParserException(e.getMessage());

        }
    }

    public JsBool False(final JsonReader reader) throws JsParserException {
        try {
            if (reader.wasFalse()) return JsBool.FALSE;
            throw reader.newParseErrorAt("Found invalid boolean value. False was expected.",
                                         0
                                        );
        } catch (ParsingException e) {
            throw new JsParserException(e.getMessage());

        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy