项目作者: pjfanning

项目描述 :
Jackson support for Scala3 enums
高级语言: Scala
项目地址: git://github.com/pjfanning/jackson-module-scala3-enum.git
创建时间: 2021-01-02T16:42:30Z
项目社区:https://github.com/pjfanning/jackson-module-scala3-enum

开源协议:Apache License 2.0

下载


jackson-module-scala3-enum

Build Status
Maven Central

Jackson support for Scala3 enums.

This was moved into the main jackson-module-scala lib in its 2.17.0 release (https://github.com/FasterXML/jackson-module-scala/issues/501). So there will be no further releases of this separate lib. DefaultScalaModule includes this module.

  1. libraryDependencies += "com.github.pjfanning" %% "jackson-module-scala3-enum" % "2.16.0"
  1. import com.github.pjfanning.`enum`.EnumModule
  2. val mapper = JsonMapper.builder()
  3. .addModule(DefaultScalaModule)
  4. .addModule(EnumModule)
  5. .build()
  6. //old approach - will not work in Jackson 3
  7. val mapper = new ObjectMapper()
  8. mapper.registerModule(DefaultScalaModule)
  9. mapper.registerModule(EnumModule)

The code uses toString on the enum instance to get the serialized value and when deserializing, valueOf(String) on the derived companion object is used. It may be possible to use Jackson annotations to modify this behaviour but there have been some issues with how the Scala 3 compiler handles Java annotations (some fixed but some still open).