ModelMapper Module for Java8

July 12, 2023 ยท View on GitHub

Build Status License Maven Central

This is a module for ModelMapper to support Java 8 features.

Java 8 Date/Time

Registers the module

modelMapper.registerModule(new Jsr310Module());

Configuration

We also support for configuration.

// using String patterns
Jsr310ModuleConfig config = Jsr310ModuleConfig.builder()
    .dateTimePattern("yyyy-MM-dd HH:mm:ss") // default is yyyy-MM-dd HH:mm:ss
    .datePattern("yyyy-MM-dd") // default is yyyy-MM-dd
    .zoneId(ZoneOffset.UTC) // default is ZoneId.systemDefault()
    .build()
modelMapper.registerModule(new Jsr310Module(config));
// using DateTimeFormatter directly
Jsr310ModuleConfig config = Jsr310ModuleConfig.builder()
    .dateTimeFormatter(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
    .dateFormatter(DateTimeFormatter.ISO_LOCAL_DATE)
    .zoneId(ZoneOffset.UTC)
    .build()
modelMapper.registerModule(new Jsr310Module(config));

Support Mappings

Source TypeDestination Type
LocalDateTimeString
LocalDateTimeLong/long
LocalDateTimeBigDecimal
LocalDateTimeBigInteger
LocalDateTimeDate
LocalDateTimeCalendar
LocalDateString
LocalDateLong/long
LocalDateBigDecimal
LocalDateBigInteger
LocalDateDate
LocalDateCalendar
OffsetDateTimeString
OffsetDateTimeLong/long
OffsetDateTimeBigDecimal
OffsetDateTimeBigInteger
OffsetDateTimeDate
OffsetDateTimeCalendar
InstantString
InstantLong/long
InstantBigDecimal
InstantBigInteger
InstantDate
InstantCalendar
StringLocalDateTime
Long/longLocalDateTime
BigDecimalLocalDateTime
BigIntegerLocalDateTime
DateLocalDateTime
CalendarLocalDateTime
StringDateTime
Long/longDateTime
BigDecimalDateTime
BigIntegerDateTime
DateDateTime
CalendarDateTime
StringOffsetDateTime
Long/longOffsetDateTime
BigDecimalOffsetDateTime
BigIntegerOffsetDateTime
DateOffsetDateTime
CalendarOffsetDateTime
StringInstant
Long/longInstant
BigDecimalInstant
BigIntegerInstant
DateInstant
CalendarInstant