8000 due date deserialization fix by durm · Pull Request #351 · timols/java-gitlab-api · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.5.1</version>
</dependency>

</dependencies>


Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/gitlab/api/models/GitlabIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -41,6 +45,7 @@ public enum Action {
@JsonProperty("downvotes")
private Integer downVotes;

@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonProperty("due_date")
private LocalDate dueDate;

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/gitlab/api/models/GitlabUser.java
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/gitlab/api/TestUtils.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}

}
Original file line number Diff line number Diff line change
@@ -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));
}
}
44 changes: 44 additions & 0 deletions src/test/resources/IssueExample.json
Original file line number Diff line number Diff line change
@@ -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
}
0