FasterXML / FasterXML/jackson-module-scala

Duplicate fields with ScalaObjectMapper

Aperta
#267 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Scala
Stelle
506
Fork
138
Merge medio
3h 6m
PR unite (30g)
48

Descrizione

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?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.