#17 Bug Mismatchexception fixed
This commit is contained in:
parent
afac3ba855
commit
29ad2fdae2
|
@ -9,6 +9,7 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
@ -25,6 +26,7 @@ import java.util.Map;
|
|||
public class JsonTaskDatabase implements TaskDatabase{
|
||||
IdProvider idProvider;
|
||||
private final URL dataSource = getClass().getResource("taskdb.json");
|
||||
private final static String INVALID_DATASOURCE_MSG = "Invalid datasource specified!";
|
||||
|
||||
private Map<Long, Task> taskMap = Collections.emptyMap();
|
||||
|
||||
|
@ -99,12 +101,16 @@ public class JsonTaskDatabase implements TaskDatabase{
|
|||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
private void writeTaskListToFile() throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(timeModule)
|
||||
.registerModule(new Jdk8Module());
|
||||
|
||||
if(dataSource != null) {
|
||||
mapper.writeValue(new File(dataSource.getFile()), taskMap);
|
||||
try {
|
||||
new ObjectMapper()
|
||||
.registerModule(timeModule)
|
||||
.registerModule(new Jdk8Module())
|
||||
.writeValue(new File(dataSource.toURI()), taskMap.values());
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IOException(INVALID_DATASOURCE_MSG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +122,8 @@ public class JsonTaskDatabase implements TaskDatabase{
|
|||
private void loadTaskListFromFile() throws IOException {
|
||||
if (dataSource != null) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(timeModule);
|
||||
mapper.registerModule(timeModule)
|
||||
.registerModule(new Jdk8Module());
|
||||
|
||||
List<Task> result;
|
||||
result = mapper.readerForListOf(Task.class).readValue(dataSource);
|
||||
|
|
Loading…
Reference in New Issue