Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnrecognizedPropertyException while reading a yaml file

While working with dropwizard,

My dropwizard service reads the config.yml file.

public void run() throws Exception {
    this.run(new String[] { "server", "src/main/resources/config.yml" });
}

Config.yml file :

database:
  # the name of your JDBC driver
  driverClass: com.mysql.jdbc.Driver

  # the username
  user: user2connect

  # the password
  password: password2connect

  # the JDBC URL
  url: jdbc:mysql://url.to.connect:port

But, I am getting an error as soon as the file is read -

Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "database" (class com.service.config.DropWizardConfiguration), not marked as ignorable (4 known properties: , "http", "httpConfiguration", "logging", "loggingConfiguration"])
 at [Source: N/A; line: -1, column: -1] (through reference chain: com.service.config.DropWizardConfiguration["database"])

After going through few topics, I realized that this might be causing because of Jackson is not able to ignore few properties.

I tried couple of things -

1) Added annotation @JsonIgnoreProperty (But not sure if I added it at expected place)

2) Jackson how to ignore properties

None of them helped. Can anyone point me what I might be missing here?

like image 567
webExplorer Avatar asked Apr 30 '14 18:04

webExplorer


1 Answers

add the following lines to your configuration class

 @Valid
 @NotNull
 @JsonProperty
 private DataSourceFactory database = new DataSourceFactory();

 public DataSourceFactory getDataSourceFactory() {
    return database;
 }
like image 194
Manu Viswam Avatar answered Sep 27 '22 17:09

Manu Viswam