Repository navigation
Closed
Description
Hello,
When I try to deserialize the following YAML file:
hostname: 'example.com'
port: 1234
isSslEnabled: trueMy test fail because of this error message:
org.opentest4j.AssertionFailedError:
Expecting value to be true but was false
Expected :true
Actual :false
Whereas I can observe that in debug mode:
The unit test:
// Given
String yamlFileName = "whenDeserializing_withValidValues.yml";
Path yamlFile =
ResourcesHelper.getResourcePath(HostValidatingPropertiesTest.class, yamlFileName);
// When
Optional<HostValidatingProperties> optionalHostValidatingProperties =
YamlDeserializer.deserialize(yamlFile, HostValidatingProperties.class);
// Then
assertThat(optionalHostValidatingProperties).isPresent();
HostValidatingProperties hostValidatingProperties = optionalHostValidatingProperties.get();
assertAll(() -> assertThat(hostValidatingProperties.getHostname()).isEqualTo("example.com"),
() -> assertThat(hostValidatingProperties.getPort()).isEqualTo(1234),
() -> assertThat(hostValidatingProperties.isSslEnabled()).isTrue());And the YamlDeserializer class:
/**
* YAML deserializer for testing purposes.
*/
public final class YamlDeserializer {
private YamlDeserializer() {
// 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.
*/
@SneakyThrows
public static <T> @NonNull Optional<T> deserialize(@NonNull Path yamlFile,
@NonNull Class<T> type) {
ConfigurationNode rootNode = buildYamlConfigurationNode(yamlFile);
return Optional.ofNullable(rootNode.get(type));
}
@SneakyThrows
private static @NonNull ConfigurationNode buildYamlConfigurationNode(@NonNull Path yamlFile) {
return YamlConfigurationLoader.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?
Thanks a lot for your time.
Metadata
Metadata
Assignees
Labels
No labels

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.