提问人:jinseok.oh 提问时间:10/31/2023 最后编辑:jinseok.oh 更新时间:10/31/2023 访问量:21
ObjectMapperBean 不会在 Spring Boot 3.1 上删除“is-getter”的“is”
ObjectMapperBean doesn't remove `is` of `is-getter` on Spring Boot 3.1
问:
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
enum class TestEnumWithIsGetter(
@get:JsonProperty("id") val id: Int,
@get:JsonProperty("name") val label: String
) {
A(1, "A"),
B(2, "B"),
C(3, "C");
fun isA() = this == A
fun isB() = this == B
fun isC() = this == C
fun getLabelString() = this.label
}
@SpringJUnitConfig(
classes = [
JacksonAutoConfiguration::class,
]
)
class JacksonTest {
@Autowired
lateinit var objectMapper: ObjectMapper
@Test
fun serializeEnumWithIsGetter(softly: BDDSoftAssertions) {
val case = TestEnumWithIsGetter.C
println(objectMapper.writeValueAsString(case))
println(
ObjectMapper()
.writeValueAsString(case)
)
// result
// {"labelString":"C","isA":false,"isB":false,"isC":true,"id":3,"name":"C"}
// {"labelString":"C","a":false,"b":false,"c":true,"id":3,"name":"C"}
}
}
当 spring boot 2.7 defaultObjectMapper bean 写入时{"labelString":"C","a":false,"b":false,"c":true,"id":3,"name":"C"}
但在迁移到 3.1 之后
defaultObjectMapper bean write{"labelString":"C","isA":false,"isB":false,"isC":true,"id":3,"name":"C"}
但是,如果在 Spring boot 3.1 上使用新的 ObjectMapper,则将{"labelString":"C","a":false,"b":false,"c":true,"id":3,"name":"C"}
我认为spring config不会删除“is”的is-getter
是否有任何配置更改?
我还想知道要写信的解决方案{"labelString":"C","a":false,"b":false,"c":true,"id":3,"name":"C"}
答: 暂无答案
下一个:如何解决杰克逊无序列化错误?
评论