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
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class AttributeDeserializer extends JsonDeserializer<AttributeImpl> {

private static Pattern p = Pattern.compile("^[0-9]");
private static Pattern dateTime = Pattern
.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,6})?(Z|[+-][0-9]{2}:[0-9]{2})");
.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?(Z|[+-][0-9]{2}:[0-9]{2})");
private static Pattern date = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}");
private static Pattern time = Pattern.compile("^[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,6})?");
private static Pattern time = Pattern.compile("^[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?");

private final boolean deserializeAsDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class CustomFieldDeserializer extends JsonDeserializer<FieldContainerImpl

private static Pattern p = Pattern.compile("^[0-9]");
private static Pattern dateTime = Pattern
.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,6})?(Z|[+-][0-9]{2}:[0-9]{2})");
.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?(Z|[+-][0-9]{2}:[0-9]{2})");
private static Pattern date = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}");
private static Pattern time = Pattern.compile("^[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,6})?");
private static Pattern time = Pattern.compile("^[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?");

private final boolean deserializeAsDate;
private final boolean deserializeNumberAsDouble;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,18 @@ public void setNestedAttributesTypedAccessor() throws IOException {
assertThat(nested.get(0).asEnum("set-nested-enum")).isInstanceOf(AttributePlainEnumValue.class);
assertThat(nested.get(0).asString("set-nested-string")).isInstanceOf(String.class);
}

@Test
public void dateDeserialization() throws IOException {
ProductVariant variant = JsonUtils.fromJsonString(stringFromResource("date-attributes.json"),
ProductVariant.class);
assertThat(variant.getAttributes()).isNotEmpty();
AttributesAccessor attributes = variant.withProductVariant(AttributesAccessor::of);
assertThat(attributes.get("datetime").getValue()).isInstanceOf(ZonedDateTime.class);
assertThat(attributes.get("datetime-simple").getValue()).isInstanceOf(ZonedDateTime.class);
assertThat(attributes.get("datetime-max").getValue()).isInstanceOf(ZonedDateTime.class);
assertThat(attributes.get("time").getValue()).isInstanceOf(LocalTime.class);
assertThat(attributes.get("time-simple").getValue()).isInstanceOf(LocalTime.class);
assertThat(attributes.get("time-max").getValue()).isInstanceOf(LocalTime.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,17 @@ public void serializeCustomFields() throws JsonProcessingException {
.isEqualTo(
"{\"bool\":true,\"string\":\"foo\",\"double\":13.0,\"double2\":13.1,\"int\":13,\"enum\":{\"key\":\"foo\",\"label\":\"foo\"},\"setNumber\":[13.0,13,13.1],\"setText\":[\"foo\",\"bar\"]}");
}

@Test
public void dateDeserialization() throws IOException {
String dateFields = stringFromResource("date-customfields.json");
CustomFields customFields = JsonUtils.fromJsonString(dateFields, CustomFields.class);
Map<String, Object> fields = customFields.getFields().values();
assertThat(fields.get("datetime")).isInstanceOf(ZonedDateTime.class);
assertThat(fields.get("datetime-simple")).isInstanceOf(ZonedDateTime.class);
assertThat(fields.get("datetime-max")).isInstanceOf(ZonedDateTime.class);
assertThat(fields.get("time")).isInstanceOf(LocalTime.class);
assertThat(fields.get("time-simple")).isInstanceOf(LocalTime.class);
assertThat(fields.get("time-max")).isInstanceOf(LocalTime.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DateTest {
@Test
public void t() throws IOException {
public void dateSerialize() throws IOException {
ZonedDateTime t = ZonedDateTime.of(2020, 1, 1, 11, 1, 9, 0, ZoneId.of("Z"));
Cart cart = Cart.builder().createdAt(t).buildUnchecked();

Expand All @@ -24,5 +24,4 @@ public void t() throws IOException {
Cart c = JsonUtils.fromJsonString(cartString, Cart.class);
Assertions.assertThat(c.getCreatedAt()).isEqualTo(t);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"attributes": [
{
"name": "datetime",
"value": "2020-01-01T13:15:00.123Z"
},
{
"name": "datetime-simple",
"value": "2020-01-01T13:15:00Z"
},
{
"name": "datetime-max",
"value": "2020-01-01T13:15:00.123456789Z"
},
{
"name": "time",
"value": "13:15:00.123"
},
{
"name": "time-simple",
"value": "13:15:00"
},
{
"name": "time-max",
"value": "13:15:00.123456789"
}

]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"fields": {
"time": "13:15:00.123",
"time-simple": "13:15:00",
"time-max": "13:15:00.123456789",
"datetime": "2020-01-01T13:15:00.123Z",
"datetime-simple": "2020-01-01T13:15:00Z",
"datetime-max": "2020-01-01T13:15:00.123456789Z"
}
}