Skip to content

Commit

Permalink
Merge pull request #292 from crowdin/fix-date-field-parse
Browse files Browse the repository at this point in the history
fix: unusual date format in response
  • Loading branch information
yevheniyJ authored Nov 12, 2024
2 parents 96e6f05 + a3f8016 commit 5b644e4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ApplicationInstallation {
private Module[] modules;
private String[] scopes;
private Permissions permissions;
private DefaultPermissions defaultPermissions;
private Object defaultPermissions;
private boolean limitReached;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.crowdin.client.core.http.impl.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import lombok.SneakyThrows;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDeserializer extends JsonDeserializer<Date> {

@Override
@SneakyThrows
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
String date = p.getText();
if (date == null || date.isEmpty()) {
return null;
}

try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
return format.parse(date);
} catch (Exception e) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.parse(date);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.fasterxml.jackson.databind.util.StdDateFormat;
import lombok.SneakyThrows;

import java.util.Date;

public class JacksonJsonTransformer implements JsonTransformer {

private final ObjectMapper objectMapper;
Expand All @@ -32,6 +34,7 @@ public JacksonJsonTransformer() {
.addDeserializer(Enum.class, new EnumDeserializer());

SimpleModule module = new SimpleModule()
.addDeserializer(Date.class, new DateDeserializer())
.addSerializer(Enum.class, new EnumSerializer())
.addDeserializer(Enum.class, new EnumDeserializer())
.addDeserializer(CrowdinApiException.class, new CrowdinApiExceptionDeserializer(cleanObjectMapper))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"logo": "/resources/images/logo.png",
"baseUrl": "https://localhost.dev",
"manifestUrl": "https://localhost.dev",
"createdAt": "2019-09-20T11:34:40+00:00",
"createdAt": "2024-03-19 11:48:24",
"modules": [
{
"key": "example-application",
Expand Down

0 comments on commit 5b644e4

Please sign in to comment.