Skip to content

[BUG] Spring @DateTimeFormat(iso = ISO.DATE_TIME) not working with Cosmos DB #34849

@GustavoOS

Description

@GustavoOS

Describe the bug
Despite expecting ISO-8601 string to be stored, the datetime is being stored as number, Applies for types LocalDateTime, Instant and ZonedDateTime and Date

Exception or Stack Trace
No exception thrown

To Reproduce

  1. Create Model with ZonedDateTime property, using @DateTimeFormat(iso = ISO.DATE_TIME) annotation
  2. Create Repository
  3. Set spring boilerplate to create model instance and trigger save method of repository
  4. Check Cosmos Explorer Items
    Model
    Code Snippet
import com.azure.spring.data.cosmos.core.mapping.Container;
import com.azure.spring.data.cosmos.core.mapping.PartitionKey;
import java.time.ZonedDateTime;
import java.util.UUID;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;

@Data
@Container(containerName = "FileMetaData")
public class MetaData {

  @Id
  UUID id;

  String safeName;
  String displayName;
  String mimeType;
  FileExtension extension;

  @DateTimeFormat(iso = ISO.DATE)
  ZonedDateTime createdAt = ZonedDateTime.now();

  @PartitionKey
  @DateTimeFormat(iso = ISO.DATE_TIME)
  ZonedDateTime deletedAt;
}

Repository

import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import java.util.List;
import java.util.UUID;
import org.springframework.stereotype.Repository;


@Repository
public interface MetaDataRepository extends CosmosRepository<MetaData, UUID> { }

Expected behavior
Expected date to be stored as an ISO-8601 string

Screenshots
image
image

Setup (please complete the following information):

  • OS: Windows 10
  • IDE: IntelliJ
  • Library/Libraries: spring-cloud-azure-starter-data-cosmos:4.7.0 (com.azure.spring)
  • Java version: 17
  • App Server/Environment: Tomcat
  • Frameworks: Spring Boot 2.7.10, Cosmos Emulator 2.14.12.0

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please check out Troubleshoot dependency version conflict article first. If it doesn't provide solution for the problem, please provide:

  • verbose dependency tree (mvn dependency:tree -Dverbose)
  • exception message, full stack trace, and any available logs
    NA

Additional context
NA

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Metadata

Metadata

Labels

ClientThis issue points to a problem in the data-plane of the library.CosmosbugThis issue requires a change to an existing behavior in the product in order to be resolved.cosmos-java-ecosystem-se-planningcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-author-feedbackWorkflow: More information is needed from author to address the issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions