Class OptionalFieldParser
java.lang.Object
io.github.grumpystuff.grumpyrest.request.stringparser.standard.OptionalFieldParser
- All Implemented Interfaces:
FromStringParser
Parses an optional field, returning an
OptionalField which wraps the parsed value (or nothing if the
field to parse is absent). The type argument fo the OptionalField is used to select the actual parser
if the field is present.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionparseFromAbsentString(Type type) "Parses" a value from an absent string.parseFromString(String s, Type type) Parses a value from a string.booleansupportsType(Type type) Checks if this parser supports the specified type.
-
Constructor Details
-
OptionalFieldParser
Constructor.- Parameters:
registry- needed to fetch the parser for the contained type at run-time
-
-
Method Details
-
supportsType
Description copied from interface:FromStringParserChecks if this parser supports the specified type.- Specified by:
supportsTypein interfaceFromStringParser- Parameters:
type- the type to check- Returns:
- true if supported, false if not
-
parseFromString
Description copied from interface:FromStringParserParses a value from a string.- Specified by:
parseFromStringin interfaceFromStringParser- Parameters:
s- the string to parsetype- the type to parse as- Returns:
- the parsed value
- Throws:
FromStringParserException- if the string does not conform to the parser's expectation
-
parseFromAbsentString
Description copied from interface:FromStringParser"Parses" a value from an absent string. This can be used to return a default for optional parameters.The standard implementation of this method is that missing values are not tolerated, and throws an exception.
- Specified by:
parseFromAbsentStringin interfaceFromStringParser- Parameters:
type- the type to parse as- Returns:
- the default value
-