13
13
import java .time .LocalDate ;
14
14
import java .time .OffsetDateTime ;
15
15
import java .time .format .DateTimeFormatter ;
16
- import Avalara .SDK .model .A1099 .V2 .*;
16
+ import Avalara .SDK .model .A1099 .V2 .*;
17
17
import Avalara .SDK .model .EInvoicing .V1 .*;
18
18
19
19
import okio .ByteString ;
@@ -40,8 +40,7 @@ public class JSON {
40
40
41
41
@ SuppressWarnings ("unchecked" )
42
42
public static GsonBuilder createGson () {
43
- GsonFireBuilder fireBuilder = new GsonFireBuilder ()
44
- ;
43
+ GsonFireBuilder fireBuilder = new GsonFireBuilder ();
45
44
GsonBuilder builder = fireBuilder .createGsonBuilder ();
46
45
return builder ;
47
46
}
@@ -55,10 +54,13 @@ private static String getDiscriminatorValue(JsonElement readElement, String disc
55
54
}
56
55
57
56
/**
58
- * Returns the Java class that implements the OpenAPI schema for the specified discriminator value.
57
+ * Returns the Java class that implements the OpenAPI schema for the specified
58
+ * discriminator value.
59
59
*
60
- * @param classByDiscriminatorValue The map of discriminator values to Java classes.
61
- * @param discriminatorValue The value of the OpenAPI discriminator in the input data.
60
+ * @param classByDiscriminatorValue The map of discriminator values to Java
61
+ * classes.
62
+ * @param discriminatorValue The value of the OpenAPI discriminator in
63
+ * the input data.
62
64
* @return The Java class that implements the OpenAPI schema
63
65
*/
64
66
private static Class getClassByDiscriminator (Map classByDiscriminatorValue , String discriminatorValue ) {
@@ -71,12 +73,12 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri
71
73
72
74
public JSON () {
73
75
gson = createGson ()
74
- .registerTypeAdapter (Date .class , dateTypeAdapter )
75
- .registerTypeAdapter (java .sql .Date .class , sqlDateTypeAdapter )
76
- .registerTypeAdapter (OffsetDateTime .class , offsetDateTimeTypeAdapter )
77
- .registerTypeAdapter (LocalDate .class , localDateTypeAdapter )
78
- .registerTypeAdapter (byte [].class , byteArrayAdapter )
79
- .create ();
76
+ .registerTypeAdapter (Date .class , dateTypeAdapter )
77
+ .registerTypeAdapter (java .sql .Date .class , sqlDateTypeAdapter )
78
+ .registerTypeAdapter (OffsetDateTime .class , offsetDateTimeTypeAdapter )
79
+ .registerTypeAdapter (LocalDate .class , localDateTypeAdapter )
80
+ .registerTypeAdapter (byte [].class , byteArrayAdapter )
81
+ .create ();
80
82
}
81
83
82
84
/**
@@ -104,7 +106,8 @@ public JSON setGson(Gson gson) {
104
106
*
105
107
* @param lenientOnJson Set it to true to ignore some syntax errors
106
108
* @return JSON
107
- * @see <a href="https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html">https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html</a>
109
+ * @see <a href=
110
+ * "https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html">https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html</a>
108
111
*/
109
112
public JSON setLenientOnJson (boolean lenientOnJson ) {
110
113
isLenientOnJson = lenientOnJson ;
@@ -134,7 +137,8 @@ public <T> T deserialize(String body, Type returnType) {
134
137
try {
135
138
if (isLenientOnJson ) {
136
139
JsonReader jsonReader = new JsonReader (new StringReader (body ));
137
- // see https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html
140
+ // see
141
+ // https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.5/com/google/gson/stream/JsonReader.html
138
142
jsonReader .setLenient (true );
139
143
return gson .fromJson (jsonReader , returnType );
140
144
} else {
@@ -216,7 +220,13 @@ public OffsetDateTime read(JsonReader in) throws IOException {
216
220
default :
217
221
String date = in .nextString ();
218
222
if (date .endsWith ("+0000" )) {
219
- date = date .substring (0 , date .length ()-5 ) + "Z" ;
223
+ date = date .substring (0 , date .length () - 5 ) + "Z" ;
224
+ }
225
+ // Handle datetime strings without timezone information by appending 'Z'
226
+ // This addresses A1099 API responses that return local datetime strings
227
+ // like '2025-05-06T23:33:25.358690' without timezone indicators
228
+ else if (!date .endsWith ("Z" ) && !date .matches (".*[+-]\\ d{2}:?\\ d{2}$" )) {
229
+ date = date + "Z" ;
220
230
}
221
231
return OffsetDateTime .parse (date , formatter );
222
232
}
@@ -283,7 +293,8 @@ public static class SqlDateTypeAdapter extends TypeAdapter<java.sql.Date> {
283
293
284
294
private DateFormat dateFormat ;
285
295
286
- public SqlDateTypeAdapter () {}
296
+ public SqlDateTypeAdapter () {
297
+ }
287
298
288
299
public SqlDateTypeAdapter (DateFormat dateFormat ) {
289
300
this .dateFormat = dateFormat ;
@@ -336,7 +347,8 @@ public static class DateTypeAdapter extends TypeAdapter<Date> {
336
347
337
348
private DateFormat dateFormat ;
338
349
339
- public DateTypeAdapter () {}
350
+ public DateTypeAdapter () {
351
+ }
340
352
341
353
public DateTypeAdapter (DateFormat dateFormat ) {
342
354
this .dateFormat = dateFormat ;
0 commit comments