#17 implementation JsonTaskDatabase.java, gradle import for jackson

This commit is contained in:
Gian-Andrea Hutter 2022-10-24 12:43:50 +02:00
parent e228b9019d
commit 904041afc0
1 changed files with 14 additions and 0 deletions

View File

@ -4,10 +4,12 @@ import ch.zhaw.gartenverwaltung.types.Task;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.deser.MonthDayDeserializer;
import javafx.util.converter.LocalDateStringConverter;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.time.MonthDay;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
@ -18,6 +20,18 @@ import java.util.Optional;
public class JsonTaskDatabase implements TaskDatabase{
private final URL dataSource = getClass().getResource("taskdb.json");
public static void main(String[] args) {
Date date = new Date();
Date yesterday = new Date(-1);
Task testTask = new Task("water", "apply water", date);
JsonTaskDatabase jsonTaskDatabase = new JsonTaskDatabase();
try {
jsonTaskDatabase.saveTask(testTask);
System.out.println(jsonTaskDatabase.getTaskList(yesterday,date));
} catch (Exception e){
System.out.println("Task saving failed!");
}
}
private final static JavaTimeModule timeModule = new JavaTimeModule();
static {
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("MM-dd");