diff --git a/build.gradle b/build.gradle index c9fd7ac3..b5a2c100 100644 --- a/build.gradle +++ b/build.gradle @@ -23,17 +23,18 @@ repositories { } dependencies { - compile(group: 'org.slf4j', name: 'slf4j-api', version: '1.8.0-beta2') - compile(group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.5.+") - compile(group: "commons-io", name: "commons-io", version: "2.4") - testCompile(group: "org.hamcrest", name: "hamcrest-all", version: "1.3") - testCompile(group: 'org.mockito', name: 'mockito-core', version: '2.18.3') - testCompile(group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0') - testCompile(group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.0') - testCompile(group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0') - testRuntime(group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.2.0') - testCompile(group: "junit", name: "junit", version: "4.12") - testRuntime(group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.2.0') + compile(group: "org.slf4j", name: "slf4j-api", version: "1.8.0-beta2") + compile(group: "commons-io", name: "commons-io", version: "2.4") + compile(group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.5.+") + compile(group: "com.fasterxml.jackson.datatype", name: "jackson-datatype-jsr310", version: "2.5.1") + testCompile(group: "org.apache.logging.log4j", name: "log4j-api", version: "2.11.0") + testCompile(group: "org.apache.logging.log4j", name: "log4j-slf4j-impl", version: "2.11.0") + testCompile(group: "org.hamcrest", name: "hamcrest-all", version: "1.3") + testCompile(group: "org.mockito", name: "mockito-core", version: "2.18.3") + testCompile(group: "org.junit.jupiter", name: "junit-jupiter-api", version: "5.2.0") + testCompile(group: "junit", name: "junit", version: "4.12") + testRuntime(group: "org.junit.jupiter", name: "junit-jupiter-engine", version: "5.2.0") + testRuntime(group: "org.junit.vintage", name: "junit-vintage-engine", version: "5.2.0") } jar { diff --git a/pom.xml b/pom.xml index f61b6cd0..157b0e94 100644 --- a/pom.xml +++ b/pom.xml @@ -151,6 +151,13 @@ ${log4j.version} test + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.5.1 + + diff --git a/src/main/java/org/gitlab/api/models/GitlabIssue.java b/src/main/java/org/gitlab/api/models/GitlabIssue.java index de62fb5a..046fe609 100644 --- a/src/main/java/org/gitlab/api/models/GitlabIssue.java +++ b/src/main/java/org/gitlab/api/models/GitlabIssue.java @@ -4,8 +4,12 @@ import java.util.Date; import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +@JsonIgnoreProperties(ignoreUnknown = true) public class GitlabIssue { public enum Action { @@ -41,6 +45,7 @@ public enum Action { @JsonProperty("downvotes") private Integer downVotes; + @JsonDeserialize(using = LocalDateDeserializer.class) @JsonProperty("due_date") private LocalDate dueDate; diff --git a/src/main/java/org/gitlab/api/models/GitlabUser.java b/src/main/java/org/gitlab/api/models/GitlabUser.java index 840c6f86..9f6cff5f 100644 --- a/src/main/java/org/gitlab/api/models/GitlabUser.java +++ b/src/main/java/org/gitlab/api/models/GitlabUser.java @@ -1,10 +1,12 @@ package org.gitlab.api.models; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.Date; import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; - +@JsonIgnoreProperties(ignoreUnknown = true) public class GitlabUser { public static String URL = "/users"; diff --git a/src/test/java/org/gitlab/api/TestUtils.java b/src/test/java/org/gitlab/api/TestUtils.java new file mode 100644 index 00000000..71bbe027 --- /dev/null +++ b/src/test/java/org/gitlab/api/TestUtils.java @@ -0,0 +1,18 @@ +package org.gitlab.api; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.stream.Collectors; + +public class TestUtils { + public static String readDataFromResource(String path) throws IOException { + InputStream inputStream = TestUtils.class.getClassLoader().getResourceAsStream(path); + assert inputStream != null; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + return reader.lines().collect(Collectors.joining("\n")); + } + } + +} diff --git a/src/test/java/org/gitlab/api/models/GitlabIssueDeserializationTest.java b/src/test/java/org/gitlab/api/models/GitlabIssueDeserializationTest.java new file mode 100644 index 00000000..52802671 --- /dev/null +++ b/src/test/java/org/gitlab/api/models/GitlabIssueDeserializationTest.java @@ -0,0 +1,17 @@ +package org.gitlab.api.models; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.gitlab.api.TestUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +class GitlabIssueDeserializationTest { + @Test + void deserializationTest() { + ObjectMapper objectMapper = new ObjectMapper(); + Assertions.assertDoesNotThrow(() -> objectMapper.readValue( + TestUtils.readDataFromResource("IssueExample.json"), GitlabIssue.class)); + } +} diff --git a/src/test/resources/IssueExample.json b/src/test/resources/IssueExample.json new file mode 100644 index 00000000..66936686 --- /dev/null +++ b/src/test/resources/IssueExample.json @@ -0,0 +1,44 @@ +{ + "id":231, + "iid":2456, + "project_id":871, + "title":"Data Feed Dghrythfh00", + "description":"# Bountyrdhfy.", + "state":"opened", + "created_at":"2019-06-06T21:54:50.241Z", + "updated_at":"2019-06-08T17:22:59.613Z", + "closed_at":null, + "closed_by":null, + "labels":[ + "bounty::available", + "status::untouched" + ], + "milestone":null, + "assignees":[ + + ], + "author":{ + "id":1325, + "name":"jlsfldgs", + "username":"jlsfldgsd", + "state":"active", + "avatar_url":"https://assets.gitlab-static.net/uploads/-/system/user/avatar/139453452225/avatar.png", + "web_url":"https://gitlab.com/jlsfldgsd" + }, + "assignee":null, + "user_notes_count":4, + "merge_requests_count":0, + "upvotes":0, + "downvotes":0, + "due_date":"2019-06-29", + "confidential":false, + "discussion_locked":null, + "web_url":"https://gitlab.com/3456457", + "time_stats":{ + "time_estimate":0, + "total_time_spent":0, + "human_time_estimate":null, + "human_total_time_spent":null + }, + "weight":null +} \ No newline at end of file