Skip to content

Commit e54f965

Browse files
authored
Do not mix mapper types in JsonData serialization (#440)
1 parent d5b93c9 commit e54f965

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

java-client/src/main/java/co/elastic/clients/json/JsonDataImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ public <T> T deserialize(JsonpDeserializer<T> deserializer, JsonpMapper mapper)
108108
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
109109
if (value instanceof JsonValue) {
110110
generator.write((JsonValue) value);
111+
} else if (this.mapper == null) {
112+
mapper.serialize(value, generator);
113+
} else if (this.mapper.getClass() != mapper.getClass()) {
114+
// Workaround for https://github.com/elastic/elasticsearch-java/issues/424
115+
// Mappers can require generators to have been created by them (see JacksonJsonpMapper), so use the mapper
116+
// parameter if its class is different from the one passed at construction time.
117+
mapper.serialize(value, generator);
111118
} else {
112-
// Mapper provided at creation time has precedence
113-
(this.mapper != null ? this.mapper : mapper).serialize(value, generator);
119+
this.mapper.serialize(value, generator);
114120
}
115121
}
116122

0 commit comments

Comments
 (0)