Skip to content

Commit 9c36e21

Browse files
Do not mix mapper types in JsonData serialization (#440) (#442)
Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
1 parent 89c6570 commit 9c36e21

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
@@ -96,9 +96,15 @@ public <T> T deserialize(JsonpDeserializer<T> deserializer, JsonpMapper mapper)
9696
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
9797
if (value instanceof JsonValue) {
9898
generator.write((JsonValue) value);
99+
} else if (this.mapper == null) {
100+
mapper.serialize(value, generator);
101+
} else if (this.mapper.getClass() != mapper.getClass()) {
102+
// Workaround for https://github.com/elastic/elasticsearch-java/issues/424
103+
// Mappers can require generators to have been created by them (see JacksonJsonpMapper), so use the mapper
104+
// parameter if its class is different from the one passed at construction time.
105+
mapper.serialize(value, generator);
99106
} else {
100-
// Mapper provided at creation time has precedence
101-
(this.mapper != null ? this.mapper : mapper).serialize(value, generator);
107+
this.mapper.serialize(value, generator);
102108
}
103109
}
104110

0 commit comments

Comments
 (0)