Skip to content

Commit

Permalink
Add failing test for #279 (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Aug 15, 2024
1 parent f71fbf2 commit a8776a6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public WrapperWithReadTimestampsAsNanosEnabled() { }
public WrapperWithReadTimestampsAsNanosEnabled(OffsetDateTime v) { value = v; }
}

private ObjectMapper MAPPER = newMapper();
private final ObjectMapper MAPPER = newMapper();

@Test
public void testDeserializationAsFloat01WithoutTimeZone() throws Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.fasterxml.jackson.datatype.jsr310.failing;

import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;

import org.junit.Test;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.ModuleTestBase;

import static org.junit.Assert.assertEquals;

public class OffsetDateTimeDeser279Test extends ModuleTestBase
{
// For [modules-java8#279]
static class Wrapper279 {
OffsetDateTime date;

public Wrapper279(OffsetDateTime d) { date = d; }
protected Wrapper279() { }

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
public OffsetDateTime getDate() {
return date;
}
public void setDate(OffsetDateTime date) {
this.date = date;
}
}

private ObjectMapper MAPPER = newMapper();

// For [modules-java8#279]
@Test
public void testWrapperWithPattern279() throws Exception
{
final OffsetDateTime date = OffsetDateTime.now(ZoneId.of("UTC"))
.truncatedTo(ChronoUnit.SECONDS);
final Wrapper279 input = new Wrapper279(date);
final String json = MAPPER.writeValueAsString(input);

Wrapper279 result = MAPPER.readValue(json, Wrapper279.class);
assertEquals(input.date, result.date);
}
}

0 comments on commit a8776a6

Please sign in to comment.