- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 143
Closed
Milestone
Description
Jackson version 2.9.1
I would like to serialized Some(List.empty) to []
import java.io.StringWriter
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
case class Test(opt: Option[List[String]] = Some(List.empty))
val mapper = new ObjectMapper with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_ABSENT, JsonInclude.Include.ALWAYS))
val nonEmptyList = new StringWriter
mapper.writeValue(nonEmptyList, Test(Some(List("hello", "world"))))
nonEmptyList.toString // {"opt":["hello","world"]}
val emptyList = new StringWriter
mapper.writeValue(emptyList, Test(Some(List())))
emptyList.toString // {} should be {"opt": []} !?
val emptyOption = new StringWriter
mapper.writeValue(emptyOption, Test(None))
emptyOption.toString // {}
david-convey
Metadata
Metadata
Assignees
Labels
No labels