You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure exactly what's going on here. A public field gets serialized fine, until I set the visibility using PropertyAccessor.GETTER.
~/test ❯❯❯ cat src/main/scala/Test.scala
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility
import java.io.StringWriter
object Test extends App {
val serializer = new ObjectMapper
serializer.registerModule(DefaultScalaModule)
//serializer.setVisibility(PropertyAccessor.GETTER, Visibility.NONE)
serializer.setVisibility(PropertyAccessor.FIELD, Visibility.PROTECTED_AND_PUBLIC)
val test = new Test
test.addString("a")
println(test.toJson)
}
class Test {
var entries = Seq[String]()
def addString(str: String) = {
entries = entries :+ str
}
def toJson(): String = {
val writer = new StringWriter
Test.serializer.writeValue(writer, this)
return writer.toString
}
}
produces {"entries":["a"]}, but uncommenting the GETTER line produces {}. Not sure if I'm missing something about the way PropretyAccessor.GETTER works, but this seems like a bug.
Here's my build.sbt as well, in case it's a version-specific problem:
Not sure exactly what's going on here. A public field gets serialized fine, until I set the visibility using
PropertyAccessor.GETTER
.produces
{"entries":["a"]}
, but uncommenting theGETTER
line produces{}
. Not sure if I'm missing something about the wayPropretyAccessor.GETTER
works, but this seems like a bug.Here's my
build.sbt
as well, in case it's a version-specific problem:The text was updated successfully, but these errors were encountered: