Class LegacyParserAdapter
- All Implemented Interfaces:
ConfigConverter<Object>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Class<? extends ConfigParser> Converts aNumberto the wrapper at the same index ofWIDENING_ORDER.The numeric wrappers in JLS 5.1.2 widening order: every conversion from an earlier entry to a later one is a widening primitive conversion, and no other conversion between them is. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Class<?> fromPlain(Object plain, ConversionContext context) Converts plain data to a Java value.private static ObjectlegacyInput(Object plain, ConverterRegistry.Context ctx) private ConfigParser<?> toPlain(Object value, ConversionContext context) Converts a Java value to plain data.(package private) static ObjectwidenToFieldType(Class<?> fieldType, Object value) Gives a boxed numeric field exactly the widening conversions its primitive already gets.
-
Field Details
-
WIDENING_ORDER
The numeric wrappers in JLS 5.1.2 widening order: every conversion from an earlier entry to a later one is a widening primitive conversion, and no other conversion between them is. -
WIDENERS
Converts aNumberto the wrapper at the same index ofWIDENING_ORDER. -
parserClass
-
-
Constructor Details
-
LegacyParserAdapter
- Parameters:
parserClass- legacy parser's public no-argument implementation
-
-
Method Details
-
toPlain
Description copied from interface:ConfigConverterConverts a Java value to plain data.- Specified by:
toPlainin interfaceConfigConverter<Object>- Parameters:
value- the Java valuecontext- the immutable conversion location and recursive dispatcher- Returns:
- plain data
- Throws:
ConversionException- when conversion cannot preserve the value
-
fromPlain
Description copied from interface:ConfigConverterConverts plain data to a Java value.- Specified by:
fromPlainin interfaceConfigConverter<Object>- Parameters:
plain- the value read from the documentcontext- the immutable conversion location and recursive dispatcher- Returns:
- the Java value
- Throws:
ConversionException- when the input cannot be converted
-
parser
- Throws:
ConversionException
-
widenToFieldType
Gives a boxed numeric field exactly the widening conversions its primitive already gets.SnakeYAML hands back an
Integerfor a whole number such as1800.Field.setwidens that into alongordoublefield, but it refuses the same value for aLong,DoubleorFloatfield (measured:IllegalArgumentException: Can not set java.lang.Long field ... to java.lang.Integer). A boxed field therefore loaded on the first boot, when the key was missing and the field default was written, and threw on every later boot and on every reload (#531, gate-1 CR-01).Only the JLS 5.1.2 widening primitive conversions are applied, so a boxed field accepts exactly what its primitive accepts:
ShortfromByte;IntegerfromByte/Short;LongfromByte/Short/Integer;Floatfrom any integral value;Doublefrom any integral value or aFloat. Anything else -- a narrowing conversion, a non-numeric value, a field that is not a numeric wrapper -- is returned unchanged, soField.setrefuses it exactly as before.- Parameters:
fieldType- the declared type of the target fieldvalue- the parsed value- Returns:
valuewidened tofieldType, orvalueitself
-
boxed
-
legacyInput
private static Object legacyInput(Object plain, ConverterRegistry.Context ctx) throws ConversionException - Throws:
ConversionException
-