You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * YAML deserializer for testing purposes. */publicfinalclassYamlDeserializer {
privateYamlDeserializer() {
// Static class
}
/** * Deserializes the given YAML file into the specified type. * * @param yamlFile The YAML content to deserialize. * @param type The expected type of the YAML content. * @return The deserialized value if present and of valid type. * @param <T> The expected type to be obtained from deserialization. */@SneakyThrowspublicstatic <T> @NonNullOptional<T> deserialize(@NonNullPathyamlFile,
@NonNullClass<T> type) {
ConfigurationNoderootNode = buildYamlConfigurationNode(yamlFile);
returnOptional.ofNullable(rootNode.get(type));
}
@SneakyThrowsprivatestatic@NonNullConfigurationNodebuildYamlConfigurationNode(@NonNullPathyamlFile) {
returnYamlConfigurationLoader.builder().path(yamlFile).build().load();
}
}
Do you have any idea about why finally the deserialized boolean value has been converted to false? Is it a bug?
I suspect that the behavior come from HostValidatingProperties effectively:
/** * Represents an annotated Java Beans version of an {@link HostProperties}. */@ConfigSerializable@Data@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
publicfinalclassHostValidatingPropertiesextendsValidatingConvertibleProperties<HostProperties> {
/** * An hostname cannot exceed 255 characters as per the DNS standard specification. */@NotBlank@Size(max = 255)
privateStringhostname;
/** * A port cannot exceed 65535, which is the maximum value allowed by the Transport Control * Protocol (TCP) and User Datagram Protocol (UDP) standards. */@Max(65535)
@PositiveOrZeroprivateintport;
privatebooleanisSslEnabled;
@Overrideprotected@NonNullHostPropertiesconvertValidated() {
returnHostProperties.of(hostname, port, isSslEnabled);
}
}
And the parent class ValidatingConvertibleProperties:
/** * Represents a convertible data structure after validation which provides a way to convert it to * its final form. * * <p>This approach allows for decoupling the validation and the final data structure creation. * * @param <T> The type of the final data structure. */@EqualsAndHashCode@ToStringpublicabstractclassValidatingConvertibleProperties<T> {
privatebooleanisValidated = false;
/** * Marks the properties as validated. */publicvoidmarkAsValidated() {
this.isValidated = true;
}
/** * Converts the properties to the "ready to use" data structure version. * * @return The "ready to use" data structure version. * @throws IllegalStateException if properties have not been validated before the conversion. */publicTconvert() {
if (!isValidated) {
thrownewIllegalStateException("Properties must be validated before being converted");
}
returnconvertValidated();
}
/** * Converts the data from the current instance of the class inheriting this. * * <p><i>Note: This method must be called only after the data structure validation. * * @return The converted final data structure. */@NonNullprotectedabstractTconvertValidated();
}
I suspect a conflict with the boolean value isValidated: it is supposed to remain false.
Activity
[-]Boolean value deserialization (unit test context)[/-][+]Boolean value YAML deserialization (unit test context)[/+][-]Boolean value YAML deserialization (unit test context)[/-][+]Unexpected boolean value on YAML deserialization[/+]Djaytan commentedon Jan 20, 2023
Same issue with Hocon config file with
configurate-hoconmodule:{ hostname: "example.com", port: 1234, isSslEnabled: true }[-]Unexpected boolean value on YAML deserialization[/-][+]Unexpected boolean value on deserialization[/+]zml2008 commentedon Jan 20, 2023
This sounds like it's some issue with HostValidatingProperties, do you have that class handy?
Djaytan commentedon Jan 20, 2023
I suspect that the behavior come from
HostValidatingPropertieseffectively:And the parent class
ValidatingConvertibleProperties:I suspect a conflict with the boolean value
isValidated: it is supposed to remainfalse.Djaytan commentedon Jan 20, 2023
I have updated the corresponding test:
And no problem about the
isValidatedone: the value isfalseas expected.