From 9f41585f02b0487145ba9106f2539df28230da57 Mon Sep 17 00:00:00 2001 From: Vladislav Plakhov Date: Wed, 3 Mar 2021 16:02:01 +0400 Subject: [PATCH] Support for Java 8 Date/Time API in parameters #125 add support java.sql.Time --- .../haulmont/addon/restapi/api/common/RestParseUtils.java | 6 +++++- .../haulmont/rest/demo/core/app/PortalTestServiceBean.java | 2 +- .../haulmont/rest/demo/http/rest/ServicesControllerFT.java | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/rest-api/src/com/haulmont/addon/restapi/api/common/RestParseUtils.java b/modules/rest-api/src/com/haulmont/addon/restapi/api/common/RestParseUtils.java index 7e5b715..9ac37d7 100644 --- a/modules/rest-api/src/com/haulmont/addon/restapi/api/common/RestParseUtils.java +++ b/modules/rest-api/src/com/haulmont/addon/restapi/api/common/RestParseUtils.java @@ -105,7 +105,11 @@ public Object toObject(Type type, String value, @Nullable String modelVersion) t return Datatypes.getNN(OffsetTime.class).parse(value); } if (Time.class == clazz) { - return Datatypes.getNN(Time.class).parse(value); + LocalTime result = Datatypes.getNN(LocalTime.class).parse(value); + if (result == null) { + return null; + } + return Time.valueOf(result); } if (BigDecimal.class == clazz) return Datatypes.getNN(BigDecimal.class).parse(value); if (Boolean.class == clazz || Boolean.TYPE == clazz) return Datatypes.getNN(Boolean.class).parse(value); diff --git a/test/restapi-demo/modules/core/src/com/haulmont/rest/demo/core/app/PortalTestServiceBean.java b/test/restapi-demo/modules/core/src/com/haulmont/rest/demo/core/app/PortalTestServiceBean.java index f8d8be4..9e173e5 100644 --- a/test/restapi-demo/modules/core/src/com/haulmont/rest/demo/core/app/PortalTestServiceBean.java +++ b/test/restapi-demo/modules/core/src/com/haulmont/rest/demo/core/app/PortalTestServiceBean.java @@ -61,7 +61,7 @@ public String convertDate(LocalDate localDate, LocalDateTime localDateTime, Loca builder.append(localDateTime.toString()).append(","); builder.append(localTime.toString()).append(","); builder.append(offsetDateTime.toString()).append(","); - builder.append(offsetTime.toString()); + builder.append(offsetTime.toString()).append(","); builder.append(time.toString()); return builder.toString(); } diff --git a/test/restapi-demo/modules/portal/test/com/haulmont/rest/demo/http/rest/ServicesControllerFT.java b/test/restapi-demo/modules/portal/test/com/haulmont/rest/demo/http/rest/ServicesControllerFT.java index 0b408f6..5466730 100644 --- a/test/restapi-demo/modules/portal/test/com/haulmont/rest/demo/http/rest/ServicesControllerFT.java +++ b/test/restapi-demo/modules/portal/test/com/haulmont/rest/demo/http/rest/ServicesControllerFT.java @@ -79,7 +79,7 @@ public void serviceWithDateParams() throws Exception { String requestBody = getFileContent("serviceWithDateParams.json", null); try (CloseableHttpResponse response = sendPost("/services/" + PortalTestService.NAME + "/convertDate", oauthToken, requestBody, null)) { assertEquals(HttpStatus.SC_OK, statusCode(response)); - assertEquals("2021-02-24,2021-02-24T15:15:15.053,15:15:15,2021-02-24T15:15:15.053+04:00,15:15:15+04:00", responseToString(response)); + assertEquals("2021-02-24,2021-02-24T15:15:15.053,15:15:15,2021-02-24T15:15:15.053+04:00,15:15:15+04:00,15:15:15", responseToString(response)); } }