I have this method that maps a yaml configuration file to a class , but the mapping apparently is not OK, as shown in the bellow image, instead of mapping 60 to the default
attribute it concatenates the next attribute name which causes an exception as default
is an int
and the retrieved value is a string
.
Does anyone have any clue about why this is happening?
I tried adding a \n
after 60 to force a line break without success. ( it was working fine until I updated the file , changed 30 to 60 in defaultLangId ).
The Yaml file content :
defaultLangId : 60
- code: AR
label: ar
last-result-index : 120
My config calss :
@Getter
@Setter
public class XXXXXConfiguration {
private int defaultLangId;
private List<CodeLabel> cities;
private int lastResultIndex;
}
CodePudding user response:
The line after 60
is more indented. This causes YAML to read it as continuation of the scalar 60
, resulting in 60 - code
(for -
to be considered a sequence item indicator, it must not be inside a scalar). Only when :
is encountered, the value is finalized because :
can end a scalar.
Your class indicates that you want to give a sequence that is to be loaded into the field cities
; you need to give the key cities
in your YAML for that:
defaultLangId : 60
cities:
- code: AR
label: ar
last-result-index : 120