Skip to content

Commit 6a4050e

Browse files
committed
write RenderableDate to JSON correctly.
1 parent 0438c2a commit 6a4050e

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/RenderableDate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Thomas Akehurst
2+
* Copyright (C) 2018-2024 Thomas Akehurst
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package com.github.tomakehurst.wiremock.extension.responsetemplating.helpers;
1717

18+
import com.fasterxml.jackson.annotation.JsonValue;
1819
import com.fasterxml.jackson.databind.util.ISO8601Utils;
1920
import java.text.SimpleDateFormat;
2021
import java.time.ZoneId;
@@ -42,6 +43,7 @@ public ZoneId getTimezone() {
4243
}
4344

4445
@Override
46+
@JsonValue
4547
public String toString() {
4648
if (format != null) {
4749
if (format.equals("epoch")) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2024 Thomas Akehurst
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.tomakehurst.wiremock.extension.responsetemplating.helpers;
17+
18+
import static org.hamcrest.MatcherAssert.assertThat;
19+
import static org.hamcrest.Matchers.is;
20+
21+
import com.github.tomakehurst.wiremock.common.Json;
22+
import java.util.Date;
23+
import org.junit.jupiter.api.Test;
24+
25+
public class RenderableDateTest {
26+
27+
@Test
28+
void writesToJsonInStringFormat() {
29+
RenderableDate renderableDate = new RenderableDate(new Date(1729266504000L), null, null);
30+
assertThat(Json.write(renderableDate), is("\"2024-10-18T15:48:24Z\""));
31+
}
32+
}

0 commit comments

Comments
 (0)