Je veux charger un fichier yaml & le stocker dans Config.java.La valeur du fichier Yaml ne se charge pas en utilisant jackson dans java
Voici mon fichier YAML: (. Il est beaucoup plus que je donne une version simplifiée)
---
application:
admin:
jobInterValTime: 1440
customer: lc
system:
mongo:
host: localhost
port: 27017
dbName: LC_Test
collections:
groupsCollection: groups
membershipCollection: memberships
personsCollection: persons
Voici Config.java:
public class Config {
private Application application;
private System system;
//Getter setter
}
Application.java
public class Application {
private Admin admin;
//Getter Setter
}
Admin.java
public class Admin {
private String jobInterValTime;
private String customer;
//Getter Setter
}
System.java
public class System {
private Mongo mongo;
//Getter Setter
}
Mongo.java
public class Mongo {
private String host;
private String port;
private String dbName;
private Map<String, String> collections;
//Getter Setter
}
Mais le application
& system
objet à l'intérieur Config.java
vient exception null.No se passe. Quelqu'un peut-il aider?
Voici ce que j'ai écrit.
Config config = null;
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
try{
config = objectMapper.readValue(new File("src/test/java/resources/test1.yaml"), Config.class);
//System.out.println(application.getAdmin().getCustomer());
// System.out.println(unidataConfig.getApplication().getAdmin().getCustomer());
} catch(Exception e) {
e.printStackTrace();
}