-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5a162f
commit 122dbb1
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...asterxml/jackson/datatype/jsr310/ser/ZonedDateTimeSerializationWithJsonFormat333Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.fasterxml.jackson.datatype.jsr310.ser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase; | ||
import org.junit.Test; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
// [module-java8#333] : ZonedDateTime serialization with @JsonFormat pattern never uses it while WRITE_DATES_WITH_ZONE_ID enabled #333 | ||
public class ZonedDateTimeSerializationWithJsonFormat333Test | ||
extends ModuleTestBase | ||
{ | ||
|
||
public static class ContainerWithPattern333 { | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss z") | ||
public ZonedDateTime value; | ||
} | ||
|
||
public static class ContainerWithoutPattern333 { | ||
@JsonFormat(shape = JsonFormat.Shape.STRING) | ||
public ZonedDateTime value; | ||
} | ||
|
||
private final ObjectMapper MAPPER = mapperBuilder().enable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID).build(); | ||
|
||
@Test | ||
public void testJsonFormatOverridesSerialization() throws Exception | ||
{ | ||
// ISO-8601 string for ZonedDateTime | ||
ZonedDateTime zonedDateTime = ZonedDateTime.parse("2024-11-15T18:27:06.921054+01:00[Europe/Berlin]"); | ||
ContainerWithPattern333 input = new ContainerWithPattern333(); | ||
input.value = zonedDateTime; | ||
|
||
String json = MAPPER.writeValueAsString(input); | ||
|
||
assertEquals(a2q("{'value':'2024-11-15 18:27:06 CET'}"), json); | ||
} | ||
|
||
} |