|
16 | 16 |
|
17 | 17 | package org.springframework.cloud.function.utils;
|
18 | 18 |
|
| 19 | +import java.nio.charset.StandardCharsets; |
| 20 | +import java.time.ZonedDateTime; |
| 21 | +import java.util.Date; |
19 | 22 | import java.util.List;
|
20 | 23 | import java.util.stream.Stream;
|
21 | 24 |
|
|
27 | 30 | import org.junit.jupiter.params.ParameterizedTest;
|
28 | 31 | import org.junit.jupiter.params.provider.MethodSource;
|
29 | 32 |
|
| 33 | +import org.springframework.boot.SpringApplication; |
| 34 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
30 | 35 | import org.springframework.cloud.function.json.GsonMapper;
|
31 | 36 | import org.springframework.cloud.function.json.JacksonMapper;
|
32 | 37 | import org.springframework.cloud.function.json.JsonMapper;
|
| 38 | +import org.springframework.context.ApplicationContext; |
| 39 | +import org.springframework.context.annotation.Configuration; |
33 | 40 | import org.springframework.core.ResolvableType;
|
34 | 41 |
|
35 | 42 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -67,6 +74,16 @@ public void objectNode_isJsonStringRepresentsCollection() {
|
67 | 74 | assertThat(JsonMapper.isJsonStringRepresentsCollection(nodeAsString)).isFalse();
|
68 | 75 | }
|
69 | 76 |
|
| 77 | + // see https://github.com/spring-cloud/spring-cloud-function/issues/1189 |
| 78 | + @Test |
| 79 | + public void testJsonDateTimeConversion() { |
| 80 | + ApplicationContext context = SpringApplication.run(EmptyConfiguration.class); |
| 81 | + JsonMapper jsonMapper = context.getBean(JsonMapper.class); |
| 82 | + StringVsTimestamp dom = new StringVsTimestamp("2024-10-16T16:13:29.964361+02:00"); |
| 83 | + String convertedJson = new String(jsonMapper.toJson(dom), StandardCharsets.UTF_8); |
| 84 | + assertThat(convertedJson).contains("\"zonedDateTime\":\"2024-10-16T16:13:29.964361+02:00\""); |
| 85 | + } |
| 86 | + |
70 | 87 | @ParameterizedTest
|
71 | 88 | @MethodSource("params")
|
72 | 89 | public void vanillaArray(JsonMapper mapper) {
|
@@ -140,4 +157,48 @@ public void setValue(String value) {
|
140 | 157 |
|
141 | 158 | }
|
142 | 159 |
|
| 160 | + @EnableAutoConfiguration |
| 161 | + @Configuration |
| 162 | + static class EmptyConfiguration { |
| 163 | + |
| 164 | + } |
| 165 | + |
| 166 | + static class StringVsTimestamp { |
| 167 | + |
| 168 | + private String type; |
| 169 | + |
| 170 | + private Date date; |
| 171 | + |
| 172 | + private ZonedDateTime zonedDateTime; |
| 173 | + |
| 174 | + StringVsTimestamp(String zonedDate) { |
| 175 | + type = "StringVsTimestamp"; |
| 176 | + date = new Date(); |
| 177 | + zonedDateTime = ZonedDateTime.parse(zonedDate); |
| 178 | + } |
| 179 | + |
| 180 | + public String getType() { |
| 181 | + return type; |
| 182 | + } |
| 183 | + |
| 184 | + public void setType(String type) { |
| 185 | + this.type = type; |
| 186 | + } |
| 187 | + |
| 188 | + public Date getDate() { |
| 189 | + return date; |
| 190 | + } |
| 191 | + |
| 192 | + public void setDate(Date date) { |
| 193 | + this.date = date; |
| 194 | + } |
| 195 | + |
| 196 | + public ZonedDateTime getZonedDateTime() { |
| 197 | + return zonedDateTime; |
| 198 | + } |
| 199 | + |
| 200 | + public void setZonedDateTime(ZonedDateTime zonedDateTime) { |
| 201 | + this.zonedDateTime = zonedDateTime; |
| 202 | + } |
| 203 | + } |
143 | 204 | }
|
0 commit comments