mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Use Instant in DTO
This commit is contained in:
@@ -36,7 +36,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
|
||||
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
|
||||
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.ext.ContextResolver;
|
||||
@@ -55,7 +58,9 @@ public final class JSONContextResolver implements ContextResolver<ObjectMapper>
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public JSONContextResolver() {
|
||||
mapper = new ObjectMapper();
|
||||
mapper = new ObjectMapper()
|
||||
.registerModule(new Jdk8Module())
|
||||
.registerModule(new JavaTimeModule());
|
||||
mapper.setAnnotationIntrospector(createAnnotationIntrospector());
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.*;
|
||||
import sonia.scm.api.rest.resources.UserResource;
|
||||
import sonia.scm.security.Role;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -36,4 +34,9 @@ public abstract class User2UserDtoMapper {
|
||||
}
|
||||
target.setLinks(links);
|
||||
}
|
||||
|
||||
@Mappings({@Mapping(target = "lastModified"), @Mapping(target = "creationDate")})
|
||||
Instant mapTime(Long epochMilli) {
|
||||
return epochMilli == null? null: Instant.ofEpochMilli(epochMilli);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,16 @@ package sonia.scm.api.v2.resources;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class UserDto {
|
||||
private boolean active;
|
||||
private boolean admin;
|
||||
private Long creationDate;
|
||||
private Instant creationDate;
|
||||
private String displayName;
|
||||
private Long lastModified;
|
||||
private Instant lastModified;
|
||||
private String mail;
|
||||
private String name;
|
||||
private String password;
|
||||
|
||||
@@ -2,12 +2,11 @@ package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.shiro.authc.credential.PasswordService;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Named;
|
||||
import org.mapstruct.*;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static sonia.scm.api.rest.resources.UserResource.DUMMY_PASSWORT;
|
||||
|
||||
@Mapper
|
||||
@@ -30,6 +29,10 @@ public abstract class UserDto2UserMapper {
|
||||
{
|
||||
return passwordService.encryptPassword(password);
|
||||
}
|
||||
}
|
||||
|
||||
@Mappings({@Mapping(target = "lastModified"), @Mapping(target = "creationDate")})
|
||||
Long mapTime(Instant instant) {
|
||||
return instant == null? null: instant.toEpochMilli();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user