From 904041afc0fb5ae0f21f59eb6602c78bb64143ae Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Mon, 24 Oct 2022 12:43:50 +0200 Subject: [PATCH] #17 implementation JsonTaskDatabase.java, gradle import for jackson --- .../zhaw/gartenverwaltung/io/JsonTaskDatabase.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java index c6a52a2..1889706 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonTaskDatabase.java @@ -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");