Skip to content

Commit

Permalink
Merge pull request #7 from dm-drogeriemarkt/local-time
Browse files Browse the repository at this point in the history
add default serializer for LocalTime
  • Loading branch information
waschmittel authored Feb 19, 2021
2 parents 54410c2 + f54e346 commit 28b0106
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ public class TimeMachine {

## Changes

### 2.0.1

* Added proper serialization for missing JSR310 type **LocalTime**

### 2.0.0

* **Breaking Changes**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/dm/prom/structuredlogging/MdcContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
Expand Down Expand Up @@ -38,6 +39,7 @@ public final class MdcContext implements java.io.Closeable {
module.addSerializer(OffsetTime.class, new ToStringSerializer());
module.addSerializer(Period.class, new ToStringSerializer());
module.addSerializer(ZonedDateTime.class, new ToStringSerializer());
module.addSerializer(LocalTime.class, new ToStringSerializer());

OBJECT_MAPPER.registerModule(module);
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/de/dm/prom/structuredlogging/ExampleBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ExampleBean {
private OffsetTime offsetTime;
private Period period;
private ZonedDateTime zonedDateTime;
private LocalTime localTime;

static ExampleBean getExample() {
LocalDateTime importantTime = LocalDateTime.of(2019, Month.JANUARY, 1, 13, 37);
Expand All @@ -41,6 +42,7 @@ static ExampleBean getExample() {
.offsetTime(OffsetTime.of(LocalTime.of(13, 37), ZoneOffset.of("+01:00")))
.period(Period.ofDays(42))
.zonedDateTime(ZonedDateTime.of(importantTime, ZoneId.of("UTC")))
.localTime(LocalTime.of(13, 37))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class MdcContextUnitTest {
"\"localDate\":\"2020-01-01\"," +
"\"offsetTime\":\"13:37+01:00\"," +
"\"period\":\"P42D\"," +
"\"zonedDateTime\":\"2019-01-01T13:37Z[UTC]\"}";
"\"zonedDateTime\":\"2019-01-01T13:37Z[UTC]\"," +
"\"localTime\":\"13:37\"" +
"}";

@RegisterExtension
public LogCapture logCapture = LogCapture.forCurrentPackage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class StructuredMdcJsonProviderUnitTest {
"\"localDate\":\"2020-01-01\"," +
"\"offsetTime\":\"13:37+01:00\"," +
"\"period\":\"P42D\"," +
"\"localTime\":\"13:37\"," +
"\"zonedDateTime\":\"2019-01-01T13:37Z[UTC]\"}}";

private Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
Expand Down

0 comments on commit 28b0106

Please sign in to comment.