为什么我从 ObjectId Spring/Mongo-RestController 获取时间戳以及如何避免?

问题描述 投票:0回答:0

我从 Kotlin Spring 和 Spring Data MongoDB 开始,并尝试遵循本教程:https://medium.com/techwasti/spring-boot-mongodb-rest-api-using-kotlin-47e49729bb21

我让一切都启动并运行,但是我的实体/文档:

@Document(collection = "products")
data class Product(
    @Id
    val id: ObjectId = ObjectId.get(),
    val name: String,
    val identifier: String,
    val owners: List<String> = listOf()
) {}

导致

[{
    "id": {
        "timestamp": 1678022555,
        "date": "2023-03-05T13:22:35.000+00:00"
    },
    "name": "Product A",
    "identifier": "prod-a",
    "owners": []
}]

虽然我是从 mongosh 得到的:

db.products.find();
[{
  _id: ObjectId("6404979bbaa085d5514f0d9d"),
  name: 'Product A',
  identifier: 'prod-a'
}]

从数据库中检索项目的代码是:

@GetMapping
fun getProducts(): ResponseEntity<List<Product>> {
    return ResponseEntity.ok(productRepository.findAll());
}
spring mongodb kotlin spring-data-mongodb
© www.soinside.com 2019 - 2024. All rights reserved.