Closed
Description
I am using Spring Boot 2.4.0.
The POJO class mapped to collection is:
@SuppressFBWarnings(value = {"EI_EXPOSE_REP", "EI_EXPOSE_REP2"},
justification = "This is a bean")
@Document(collection = "Posts")
@Data
@Builder
public class Post {
@Id
private String id;
private ActorInfo actorInfo;
private String text;
private Media media;
private int likes;
private Meta meta;
@Version
private Integer version;
@Data
@Builder
public static class Meta {
@CreatedDate // <-- this is not working
private Instant createdAt;
@LastModifiedDate // <-- this is not working
private Instant updatedAt;
private String event; // can be enum?
}
}
I am using MongoRepository to save above POJO in DB using save()
.
But I don't see the createdAt
and updatedAt
being populated in the collection.
This is what is being saved in collection:
{ "_id" : ObjectId("600fc6b23d5ebf145b7bbc0d"), "actorInfo" : { "_id" : "1", "role" : "USER" }, "text" : "Helo", "likes" : 0, "meta" : { "event" : "CREATED" }, "version" : 0, "_class" : "com.highstreet.socialmediaservice.adpater.output.type.Post" }