Skip to content

Commit f395ccf

Browse files
committed
Fix data types for many properties around dates and generic objects
Accounting API models updated Added format: date to 20 properties Added format: datetime to 22 properties Updated eNum list for 12 properties Updated string to integar for 3 properties Removed "allOf" from 26 objects so parsing will map to model class and not generic object. Replace BankAccount model class with Account class Cleaned up a lot of descriptions Early work on Files API included, but should not be considered stable.
1 parent b58c7e4 commit f395ccf

File tree

113 files changed

+3263
-1166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+3263
-1166
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Add the dependency to your pom.xml. Gradle, sbt and other build tools can be fo
7474
<dependency>
7575
<groupId>com.github.xeroapi</groupId>
7676
<artifactId>xero-java</artifactId>
77-
<version>2.1.3</version>
77+
<version>2.2.0</version>
7878
</dependency>
7979

8080

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.github.xeroapi</groupId>
55
<artifactId>xero-java</artifactId>
66
<packaging>jar</packaging>
7-
<version>2.1.3</version>
7+
<version>2.2.0</version>
88
<name>Xero-Java SDK</name>
99
<description>This is the official Java SDK for Xero API</description>
1010
<url>https://github.com/XeroAPI/Xero-Java</url>

src/main/java/com/xero/api/ApiClient.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.io.IOException;
1717
import java.io.OutputStream;
1818

19-
2019
public class ApiClient {
2120
private final String basePath;
2221
private final HttpRequestFactory httpRequestFactory;
@@ -26,11 +25,13 @@ public class ApiClient {
2625

2726
// A reasonable default object mapper. Client can pass in a chosen ObjectMapper anyway, this is just for reasonable defaults.
2827
private static ObjectMapper createDefaultObjectMapper() {
29-
ObjectMapper objectMapper = new ObjectMapper()
30-
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
31-
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
32-
.setDateFormat(new RFC3339DateFormat())
33-
.setSerializationInclusion(Include.NON_NULL);
28+
ObjectMapper objectMapper = new ObjectMapper()
29+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
30+
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
31+
.setDateFormat(new RFC3339DateFormat())
32+
.setSerializationInclusion(Include.NON_NULL);
33+
objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
34+
3435
ThreeTenModule module = new ThreeTenModule();
3536
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
3637
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.xero.api;
2+
3+
import java.io.IOException;
4+
import java.text.ParseException;
5+
import java.text.SimpleDateFormat;
6+
7+
import org.threeten.bp.*;
8+
import java.util.Date;
9+
import java.util.regex.Matcher;
10+
import java.util.regex.Pattern;
11+
12+
import com.fasterxml.jackson.core.JsonParser;
13+
import com.fasterxml.jackson.core.JsonProcessingException;
14+
import com.fasterxml.jackson.databind.DeserializationContext;
15+
import com.fasterxml.jackson.databind.JsonDeserializer;
16+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
17+
18+
public class CustomDateDeserializer extends StdDeserializer<LocalDate> {
19+
20+
private static final long serialVersionUID = 1L;
21+
22+
public CustomDateDeserializer() {
23+
this(null);
24+
}
25+
26+
public CustomDateDeserializer(Class<?> vc) {
27+
super(vc);
28+
}
29+
30+
public LocalDate deserialize(JsonParser jsonparser, DeserializationContext context)
31+
throws IOException, JsonProcessingException {
32+
String date = jsonparser.getText();
33+
LocalDate formattedDate;
34+
Pattern datePatt = Pattern.compile("^/Date\\((\\d+)([+-]\\d+)?\\)/$");
35+
Matcher m = datePatt.matcher(date);
36+
if (m.matches()) {
37+
Long l = Long.parseLong(m.group(1));
38+
formattedDate = Instant.ofEpochMilli(l).atZone(ZoneId.systemDefault()).toLocalDate();
39+
} else {
40+
throw new IllegalArgumentException("Wrong date format");
41+
}
42+
return formattedDate;
43+
}
44+
}
45+
46+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.xero.api;
2+
3+
import java.time.LocalDate;
4+
5+
import com.fasterxml.jackson.databind.module.SimpleModule;
6+
7+
public class CustomDateModule extends SimpleModule {
8+
9+
/**
10+
*
11+
*/
12+
private static final long serialVersionUID = 1L;
13+
14+
public CustomDateModule() {
15+
// addDeserializer(LocalDate.class, new CustomDateDeserializer());
16+
}
17+
}
18+
19+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.xero.api;
2+
3+
import java.io.IOException;
4+
import java.text.ParseException;
5+
import java.text.SimpleDateFormat;
6+
7+
import org.threeten.bp.*;
8+
import java.util.Date;
9+
import java.util.regex.Matcher;
10+
import java.util.regex.Pattern;
11+
12+
import com.fasterxml.jackson.core.JsonParser;
13+
import com.fasterxml.jackson.core.JsonProcessingException;
14+
import com.fasterxml.jackson.databind.DeserializationContext;
15+
import com.fasterxml.jackson.databind.JsonDeserializer;
16+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
17+
18+
public class CustomOffsetDateTimeDeserializer extends StdDeserializer<OffsetDateTime> {
19+
20+
private static final long serialVersionUID = 1L;
21+
22+
public CustomOffsetDateTimeDeserializer() {
23+
this(null);
24+
}
25+
26+
public CustomOffsetDateTimeDeserializer(Class<?> vc) {
27+
super(vc);
28+
}
29+
30+
public OffsetDateTime deserialize(JsonParser jsonparser, DeserializationContext context)
31+
throws IOException, JsonProcessingException {
32+
String date = jsonparser.getText();
33+
OffsetDateTime formattedDate;
34+
Pattern datePatt = Pattern.compile("^/Date\\((\\d+)([+-]\\d+)?\\)/$");
35+
Matcher m = datePatt.matcher(date);
36+
if (m.matches()) {
37+
Long l = Long.parseLong(m.group(1));
38+
formattedDate = Instant.ofEpochMilli(l).atZone(ZoneId.systemDefault()).toOffsetDateTime();
39+
} else {
40+
throw new IllegalArgumentException("Wrong date format");
41+
}
42+
return formattedDate;
43+
}
44+
}
45+
46+

src/main/java/com/xero/api/JsonConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public String getAccessTokenUrl() {
131131

132132
@Override
133133
public String getUserAgent() {
134-
return USER_AGENT + " " + CONSUMER_KEY + " [Xero-Java-2.1.3]";
134+
return USER_AGENT + " " + CONSUMER_KEY + " [Xero-Java-2.2.0]";
135135
}
136136

137137
@Override

0 commit comments

Comments
 (0)