小编dar*_*ico的帖子

在 Kotlin 中将枚举字段序列化为 JSON

我有一个愚蠢的问题,让我有点震惊。我有一个枚举和一个像这样的数据类:

enum class MyEventType(val typeName: String) {
    FIRST("firstEventReceived")
}

data class MyEvent(
    val id: String,
    val event: MyEventType
)
Run Code Online (Sandbox Code Playgroud)

我需要将其作为 json 字符串发送,但常见的 desearilizer 会生成这样的 json

{ 
    "id": "identifier",
    "event": "FIRST"
}
Run Code Online (Sandbox Code Playgroud)

但是我需要

{ 
    "id": "identifier",
    "event": "firstEventReceived"
}
Run Code Online (Sandbox Code Playgroud)

据我了解,kotlin 允许重写数据类中的 getter,但我没有成功......

data class MyEvent(
    val id: String
) {
    val event: MyEventType get() event.typeName
}
Run Code Online (Sandbox Code Playgroud)

但我想我错过了一些东西......

jackson kotlin

15
推荐指数
3
解决办法
2万
查看次数

如何禁用 Spring Boot Actuator 弹性搜索运行状况请求?

我有一个 Spring Boot 应用程序,它使用本地弹性搜索和 Spring Boot Actuator 2.1.2 仅用于指标目的。现在我需要实现默认的运行状况检查,因此我在配置 application.properties 类中将其打开,如下所示:

management.endpoints.web.exposure.include=...,health
management.endpoint.health.show-details=never
Run Code Online (Sandbox Code Playgroud)

它工作正常,我可以使用调用http://localhost/actuator/health 的默认实现来实现健康状态。

但有一个时刻我不喜欢。我发现每次当我得到像{"status":"UP"}执行器这样的非详细答案时,都会在以下地址进行不必要的elasticsearch调用

ElasticsearchHealthIndicator.doHealthCheck(Health.Builder builder)
Run Code Online (Sandbox Code Playgroud)

我打算摆脱无用的电话。

我可以以某种方式仅禁用此呼叫吗?

spring spring-boot spring-boot-actuator

3
推荐指数
1
解决办法
1万
查看次数