Introduce interface to be used by dto mappers with Instant fields

This commit is contained in:
René Pfeuffer
2018-09-14 15:00:09 +02:00
parent 470909199e
commit 7372f7a2ab
10 changed files with 84 additions and 70 deletions

View File

@@ -3,14 +3,8 @@ package sonia.scm.api.v2.resources;
import de.otto.edison.hal.HalRepresentation;
import org.mapstruct.Mapping;
import java.time.Instant;
public abstract class BaseMapper<T, D extends HalRepresentation> {
public abstract class BaseMapper<T, D extends HalRepresentation> implements InstantAttributeMapper {
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
public abstract D map(T modelObject);
protected Instant mapTime(Long epochMilli) {
return epochMilli == null? null: Instant.ofEpochMilli(epochMilli);
}
}

View File

@@ -0,0 +1,9 @@
package sonia.scm.api.v2.resources;
import java.time.Instant;
public interface InstantAttributeMapper {
default Instant mapTime(Long epochMilli) {
return epochMilli == null? null: Instant.ofEpochMilli(epochMilli);
}
}