I have a spring boot project using azure cosmos db for nosql as the database, using CosmosRepository
from spring-cloud-azure-starter-data-cosmos
artifact. My entity looks like this:
import java.time.LocalDateTime;
import org.springframework.data.annotation.Id;
import com.azure.spring.data.cosmos.core.mapping.Container;
import com.azure.spring.data.cosmos.core.mapping.GeneratedValue;
import lombok.Data;
@Data
@Container
public class Post {
@Id
@GeneratedValue
private String id;
private String author;
private String content;
private String imageUrl;
private LocalDateTime creationTime;
}
problem is, when persisting data, creationTime
is for some reason stored as an array (example: "creationTime": [2024, 6, 16, 16, 51, 25, 571970017]
), instead of an ISO string which I’d expect to be the default. This seemingly presents issues when using a repository method to sort posts by time (public List<Post> findAllByOrderByCreationTimeDesc();
). Is there a way to specify that LocalDateTime
be stored as an ISO string without changing creationTime
to String
and doing so manually?