Error: com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
Yaml file:
formatting.template:
fields:
- name: birthdate
type: java.lang.String
subType: java.util.Date
lenght: 10
ConfigurationProperties:
@Data
public class FormattingConfigurationProperties {
private List<Field> fields;
@Data
public static class Field {
private String name;
private String type;
private String subType;
private String lenght;
}
}
Method to read yaml
private static FormattingConfigurationProperties buildFormattingConfigurationProperties() throws IOException {
InputStream inputStream = new FileInputStream(new File("./src/test/resources/" + "application_formatting.yaml"));
YAMLMapper mapper = new YAMLMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
return mapper.readerFor(FormattingConfigurationProperties.class)
.at(/formatting/template)
.readValue(inputStream);
}
I actually solved it by changing the Yaml file, splitting formatting.template on separate lines:
formatting:
template:
fields:
- name: birthdate
type: java.lang.String
subType: java.util.Date
lenght: 10
This means that is not able to read key with dot (periods (.)). Someone know how to avoid MismatchedInputException, when the prefix is on the same line separated by dot?