#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);
|
||||
|
|
|
@ -1,50 +1,50 @@
|
|||
[
|
||||
{
|
||||
"id" : 1,
|
||||
"name" : "sow plant",
|
||||
"description": "Plant the seeds, crops in de bed.",
|
||||
"startDate" : "2022-05-01",
|
||||
"endDate" : "2022-05-01",
|
||||
"interval" : 0
|
||||
"id": 1,
|
||||
"name": "sow plant",
|
||||
"description": "Plant the seeds, crops in de bed.",
|
||||
"startDate": "2022-05-01",
|
||||
"endDate": "2022-05-01",
|
||||
"interval": 0
|
||||
},
|
||||
{
|
||||
"id" : 2,
|
||||
"name" : "water plant",
|
||||
"id": 2,
|
||||
"name": "water plant",
|
||||
"description": "water the plant, so that the soil is wet around the plant.",
|
||||
"startDate" : "2022-05-01",
|
||||
"endDate" : "2022-09-01",
|
||||
"interval" : 2
|
||||
"startDate": "2022-05-01",
|
||||
"endDate": "2022-09-01",
|
||||
"interval": 2
|
||||
},
|
||||
{
|
||||
"id" : 3,
|
||||
"name" : "fertilize plant",
|
||||
"id": 3,
|
||||
"name": "fertilize plant",
|
||||
"description": "The fertilizer has to be mixed with water. Then fertilize the plants soil with the mixture",
|
||||
"startDate" : "2022-06-01",
|
||||
"endDate" : "2022-08-01",
|
||||
"interval" : 28
|
||||
"startDate": "2022-06-01",
|
||||
"endDate": "2022-08-01",
|
||||
"interval": 28
|
||||
},
|
||||
{
|
||||
"id" : 4,
|
||||
"name" : "covering plant",
|
||||
"id": 4,
|
||||
"name": "covering plant",
|
||||
"description": "Take a big enough coverage for the plants. Cover the whole plant with a bit space between the plant and the coverage",
|
||||
"startDate" : "2022-07-01",
|
||||
"endDate" : "2022-07-01",
|
||||
"interval" : 0
|
||||
"startDate": "2022-07-01",
|
||||
"endDate": "2022-07-01",
|
||||
"interval": 0
|
||||
},
|
||||
{
|
||||
"id" : 5,
|
||||
"name" : "look after plant",
|
||||
"id": 5,
|
||||
"name": "look after plant",
|
||||
"description": "Look for pest or illness at the leaves of the plant. Check the soil around the plant, if the roots are enough covered with soil",
|
||||
"startDate" : "2022-05-01",
|
||||
"endDate" : "2022-09-01",
|
||||
"interval" : 5
|
||||
"startDate": "2022-05-01",
|
||||
"endDate": "2022-09-01",
|
||||
"interval": 5
|
||||
},
|
||||
{
|
||||
"id" : 6,
|
||||
"name" : "harvest plant",
|
||||
"id": 6,
|
||||
"name": "harvest plant",
|
||||
"description": "Pull the ripe vegetables out from the soil. Clean them with clear, fresh water. ",
|
||||
"startDate" : "2022-09-01",
|
||||
"endDate" : "2022-09-01",
|
||||
"interval" : 0
|
||||
"startDate": "2022-09-01",
|
||||
"endDate": "2022-09-01",
|
||||
"interval": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue