I'm parsing an YAML file with jackson yaml parser jackson-dataformat-yaml
and it's failing to parse the following YAML file.
environments:
linux:
- [rbenv,python-2.7]
env:
global:
# The username below should have write access to your module repository, to automatically commit new version tags.
- USERNAME=sdfasfaf
- secure: "fadfasdf"
build: |
set -o errexit
set -o nounset
#./bootstrap_factory_utils
It is having trouble parsing - USERNAME=sdfasfaf
property. Below are the pojo classes representing the YAML file.
SFYaml.java:
public class SFYaml {
private Environments environments;
private Env env;
private String build;
}
Env.java:
public class Env {
private Global[] global;
}
Global.java:
public class Global {
private String secure;
}
Method to parse the yaml file :
public String readYaml() {
YAMLFactory yamlFactory = new YAMLFactory();
YAMLMapper yMapper = new YAMLMapper(yamlFactory);
yMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
String output = "";
try {
SFYaml sfYaml = yMapper.readValue(new File(yamlPath), SFYaml.class);
output = yMapper.writeValueAsString(sfYaml);
log.info(sfYaml.getPublish());
// log.info(output);
} catch (JsonProcessingException e1) {
e1.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
return output;
}
I tried adding @JsonProperty
annotation, @JsonIgnoreProperties(ignoreUnknown = true)
and tried with various DeserializationFeature
features to disable the parsing failures but I always get the below error.
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of
com.amadeus.bitbucket.pojos.Global
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('USERNAME=sdfasfaf') at [Source: (File); line: 12, column: 7] (through reference chain: com.amadeus.bitbucket.pojos.SFYaml["env"]->com.amadeus.bitbucket.pojos.Env["global"]->java.lang.Object[][0]) at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63) at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1342) at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1031) at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:371) at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:323)
How can parse this USERNAME=sdfasfaf
property? Or use any workarounds if possible?