Skip to content

Commit 2c9b74b

Browse files
committed
Data serialization and deserialization fixes
1 parent 66c000a commit 2c9b74b

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>pl.wtx.symfonia</groupId>
77
<artifactId>symfonia-erp-webapi-client</artifactId>
8-
<version>0.1.1</version>
8+
<version>0.1.2</version>
99
<packaging>jar</packaging>
1010

1111
<name>Symfonia ERP WebAPI Client</name>

src/main/java/pl/wtx/symfonia/api/client/config/GsonConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static Gson createGson() {
1313

1414
return new GsonBuilder()
1515
.setStrictness(Strictness.LENIENT)
16-
.serializeNulls()
1716
.registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeAdapter())
1817
.registerTypeAdapter(LocalDate.class, new LocalDateAdapter())
1918
.create();

src/main/java/pl/wtx/symfonia/api/client/config/LocalDateAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
public class LocalDateAdapter implements JsonSerializer<LocalDate>, JsonDeserializer<LocalDate> {
1616

17-
private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
17+
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE;
1818

1919
@Override
2020
public JsonElement serialize(LocalDate localDate, Type typeOfSrc, JsonSerializationContext context) {
21-
return (localDate == null) ? null : new JsonPrimitive(localDate.format(formatter));
21+
return (localDate == null) ? null : new JsonPrimitive(localDate.format(FORMATTER));
2222
}
2323

2424
@Override
2525
public LocalDate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
26-
return (json == null || json.getAsString().isEmpty()) ? null : LocalDate.parse(json.getAsString(), formatter);
26+
return (json == null || json.getAsString().isEmpty()) ? null : LocalDate.parse(json.getAsString(), FORMATTER);
2727
}
2828

2929
}

src/main/java/pl/wtx/symfonia/api/client/config/OffsetDateTimeAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class OffsetDateTimeAdapter extends TypeAdapter<OffsetDateTime> {
1414

15-
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
15+
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
1616

1717
@Override
1818
public void write(JsonWriter out, OffsetDateTime value) throws IOException {

src/main/java/pl/wtx/symfonia/api/client/model/PriceOrderCriteria.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.gson.stream.JsonReader;
2121
import com.google.gson.stream.JsonWriter;
2222
import java.io.IOException;
23+
import java.time.LocalDate;
2324
import java.util.ArrayList;
2425
import java.util.Arrays;
2526
import java.util.List;
@@ -72,7 +73,7 @@ public class PriceOrderCriteria {
7273
public static final String SERIALIZED_NAME_DATE = "Date";
7374
@SerializedName(SERIALIZED_NAME_DATE)
7475
@javax.annotation.Nullable
75-
private String date;
76+
private LocalDate date;
7677

7778
public static final String SERIALIZED_NAME_CURRENCY = "Currency";
7879
@SerializedName(SERIALIZED_NAME_CURRENCY)
@@ -154,7 +155,7 @@ public void setDepartment(@javax.annotation.Nullable String department) {
154155
}
155156

156157

157-
public PriceOrderCriteria date(@javax.annotation.Nullable String date) {
158+
public PriceOrderCriteria date(@javax.annotation.Nullable LocalDate date) {
158159
this.date = date;
159160
return this;
160161
}
@@ -164,11 +165,11 @@ public PriceOrderCriteria date(@javax.annotation.Nullable String date) {
164165
* @return date
165166
*/
166167
@javax.annotation.Nullable
167-
public String getDate() {
168+
public LocalDate getDate() {
168169
return date;
169170
}
170171

171-
public void setDate(@javax.annotation.Nullable String date) {
172+
public void setDate(@javax.annotation.Nullable LocalDate date) {
172173
this.date = date;
173174
}
174175

@@ -359,9 +360,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
359360
if ((jsonObj.get("Department") != null && !jsonObj.get("Department").isJsonNull()) && !jsonObj.get("Department").isJsonPrimitive()) {
360361
throw new IllegalArgumentException(String.format("Expected the field `Department` to be a primitive type in the JSON string but got `%s`", jsonObj.get("Department").toString()));
361362
}
362-
if ((jsonObj.get("Date") != null && !jsonObj.get("Date").isJsonNull()) && !jsonObj.get("Date").isJsonPrimitive()) {
363-
throw new IllegalArgumentException(String.format("Expected the field `Date` to be a primitive type in the JSON string but got `%s`", jsonObj.get("Date").toString()));
364-
}
365363
if ((jsonObj.get("Currency") != null && !jsonObj.get("Currency").isJsonNull()) && !jsonObj.get("Currency").isJsonPrimitive()) {
366364
throw new IllegalArgumentException(String.format("Expected the field `Currency` to be a primitive type in the JSON string but got `%s`", jsonObj.get("Currency").toString()));
367365
}

0 commit comments

Comments
 (0)