Skip to content

Commit

Permalink
Do not mix mapper types in JsonData serialization (#440) (#441)
Browse files Browse the repository at this point in the history
Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
  • Loading branch information
github-actions[bot] and swallez committed Nov 7, 2022
1 parent 1d55a13 commit 532e139
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -108,9 +108,15 @@ public <T> T deserialize(JsonpDeserializer<T> deserializer, JsonpMapper mapper)
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
if (value instanceof JsonValue) {
generator.write((JsonValue) value);
} else if (this.mapper == null) {
mapper.serialize(value, generator);
} else if (this.mapper.getClass() != mapper.getClass()) {
// Workaround for https://github.com/elastic/elasticsearch-java/issues/424
// Mappers can require generators to have been created by them (see JacksonJsonpMapper), so use the mapper
// parameter if its class is different from the one passed at construction time.
mapper.serialize(value, generator);
} else {
// Mapper provided at creation time has precedence
(this.mapper != null ? this.mapper : mapper).serialize(value, generator);
this.mapper.serialize(value, generator);
}
}

Expand Down

0 comments on commit 532e139

Please sign in to comment.