Skip to content

Commit

Permalink
Ignore unknown properties in the JSON application configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit authored and Borewit committed Jan 30, 2023
1 parent 5051cfa commit 02cd2de
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/main/java/listfix/config/JsonConfigFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package listfix.config;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -53,6 +54,7 @@ public void setConfig(T jsonPojo)
protected static <T> T readJson(File jsonFile, Class<T> valueType) throws IOException
{
final ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper.reader().readValue(jsonFile, valueType);
}

Expand All @@ -63,23 +65,6 @@ public void write() throws IOException
mapper.writer().writeValue(this.jsonFile, this.jsonPojo);
}

public boolean existAndIsValid()
{
if (this.jsonFile.exists())
{
try
{
this.read();
return true;
}
catch (IOException ioException)
{
return false;
}
}
return true;
}

/**
* Loads the configuration file disk.
* If it does not exist, it will create an empty file.
Expand Down

0 comments on commit 02cd2de

Please sign in to comment.