Skip to content

pjfanning/jackson-module-scala3-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 (FasterXML/jackson-module-scala#501). So there will be no further releases of this separate lib. DefaultScalaModule includes this module.

libraryDependencies += "com.github.pjfanning" %% "jackson-module-scala3-enum" % "2.16.0"
import com.github.pjfanning.`enum`.EnumModule

val mapper = JsonMapper.builder()
  .addModule(DefaultScalaModule)
  .addModule(EnumModule)
  .build()

//old approach - will not work in Jackson 3
val mapper = new ObjectMapper()
mapper.registerModule(DefaultScalaModule)
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).

About

Jackson support for Scala3 enums

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages