Skip to content

Duplicate fields with ScalaObjectMapper #267

Open
@reverofevil

Description

@reverofevil

When there is a case class with BeanProperty-annotated field, the following code sometimes generates JSON with duplicate fields. For example, pId field gets serialized twice, as pId and pid.

private val mapper = {
  val objectMapper = new ObjectMapper with ScalaObjectMapper
  objectMapper.registerModule(DefaultScalaModule)
  objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
  objectMapper
}

def toJson[A <: AnyRef](a: A): String = {
  mapper.writeValueAsString(a)
}

It's impossible to remove BeanProperty annotation, because it's needed by another library. Also it's impossible to set BeanProperty on every field and remove ScalaObjectMapper, as such changes are numerous and would likely result in other compatibility issues. What's the proper way to fix this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions