FasterXML / FasterXML/jackson-module-scala

Duplicate fields with ScalaObjectMapper

Open
#267 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
506
Forks
138
Avg merge
3h 6m
Merged PRs (30d)
48

Description

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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.