|
27 | 27 | import org.elasticsearch.common.xcontent.XContentHelper;
|
28 | 28 | import org.elasticsearch.common.xcontent.XContentParser;
|
29 | 29 | import org.elasticsearch.common.xcontent.XContentType;
|
30 |
| -import org.elasticsearch.ingest.RandomDocumentPicks; |
31 | 30 | import org.elasticsearch.ingest.IngestDocument;
|
| 31 | +import org.elasticsearch.ingest.RandomDocumentPicks; |
32 | 32 | import org.elasticsearch.test.AbstractXContentTestCase;
|
33 | 33 | import org.elasticsearch.test.RandomObjects;
|
34 | 34 |
|
35 | 35 | import java.io.IOException;
|
| 36 | +import java.util.Arrays; |
36 | 37 | import java.util.Collections;
|
37 | 38 | import java.util.HashMap;
|
38 | 39 | import java.util.Map;
|
| 40 | +import java.util.Set; |
39 | 41 | import java.util.StringJoiner;
|
40 | 42 | import java.util.function.Predicate;
|
41 | 43 |
|
42 | 44 | import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
|
43 | 45 | import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument;
|
44 | 46 | import static org.hamcrest.Matchers.equalTo;
|
| 47 | +import static org.hamcrest.Matchers.instanceOf; |
45 | 48 | import static org.hamcrest.Matchers.is;
|
46 | 49 | import static org.hamcrest.Matchers.not;
|
47 | 50 |
|
@@ -156,6 +159,20 @@ public void testToXContent() throws IOException {
|
156 | 159 | assertThat(serializedIngestDocument, equalTo(serializedIngestDocument));
|
157 | 160 | }
|
158 | 161 |
|
| 162 | + public void testXContentHashSetSerialization() throws Exception { |
| 163 | + IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Map.of("key", Set.of("value"))); |
| 164 | + final WriteableIngestDocument writeableIngestDocument = new WriteableIngestDocument(ingestDocument); |
| 165 | + try (XContentBuilder builder = XContentFactory.jsonBuilder()) { |
| 166 | + builder.startObject(); |
| 167 | + writeableIngestDocument.toXContent(builder, EMPTY_PARAMS); |
| 168 | + builder.endObject(); |
| 169 | + Map<String, Object> map = XContentHelper.convertToMap(BytesReference.bytes(builder), false, builder.contentType()).v2(); |
| 170 | + assertThat(map.get("doc"), is(instanceOf(Map.class))); |
| 171 | + Map<String, Object> source = (Map<String, Object>) ((Map) map.get("doc")).get("_source"); |
| 172 | + assertThat(source.get("key"), is(Arrays.asList("value"))); |
| 173 | + } |
| 174 | + } |
| 175 | + |
159 | 176 | static IngestDocument createRandomIngestDoc() {
|
160 | 177 | XContentType xContentType = randomFrom(XContentType.values());
|
161 | 178 | BytesReference sourceBytes = RandomObjects.randomSource(random(), xContentType);
|
|
0 commit comments