'Invalid format for createdBy in SpringBoot Auditable
I implemented SpringBoot Auditable and everything is working fine except the createdBy is giving timestamp.
Here is my Auditable class:
@Getter
@Setter
public class Auditable {
@CreatedDate
private LocalDateTime createdAt;
@LastModifiedDate
private LocalDateTime updatedAt;
@CreatedBy
private ObjectId createdBy;
@LastModifiedBy
private ObjectId updatedBy;
}
And here is my AuditorAwareImpl class:
public class AuditorAwareImpl implements AuditorAware<ObjectId> {
@Override
public Optional<ObjectId> getCurrentAuditor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
ObjectId userId = null;
if (authentication != null) {
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
userId = new ObjectId(userDetails.getId());
}
return Optional.of(userId);
}
}
It's(ObjectId) saving fine to DB. But when I retrieve that record, I'm getting createdBy as different format instead of ObjectId:
Can someone help me with this please?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

