我有一个简单的案例类,如下所示:
case class ColumnMetadata(name: String,
displayName: String,
description: Option[String],
attributeType: AttributeType)
sealed trait AttributeType extends EnumEntry
case object AttributeType extends Enum[AttributeType] with CirceEnum[AttributeType] {
val values: immutable.IndexedSeq[AttributeType] = findValues
case object Number extends AttributeType
case object Text extends AttributeType
case object Percentage extends AttributeType
}
和半自动编码器:
package object circe {
implicit val config: Configuration = Configuration.default.withSnakeCaseMemberNames
implicit val columnMetaDecoder: Decoder[ColumnMetadata] = deriveConfiguredDecoder
implicit val columnMetaEncoder: Encoder[ColumnMetadata] = deriveConfiguredEncoder
implicit val columnTypeDecoder: Decoder[AttributeType] = deriveConfiguredDecoder
implicit val columnTypeEncoder: Encoder[AttributeType] = deriveConfiguredEncoder
}
但是,当我进行序列化测试时:
ColumnMetadata("column1", "Column 1", Some("column1"),
AttributeType.withName("Text")).asJson
我得到:
{
"name" : "column1",
"display_name" : "Column 1",
"description" : "column1",
"attribute_type" : {
"Text": {}
}
}
当我想要:
{
"name" : "column1",
"display_name" : "Column 1",
"description" : "column1",
"attribute_type" : "Text"
}
它在我使用自动派生时有效,但我想使用半自动派生,因此我可以使用 withSnakeCaseMemberNames 等功能。