Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void readFrom(StreamInput in) throws IOException {
indicesOptions = IndicesOptions.readIndicesOptions(in);
type = in.readOptionalString();
source = in.readString();
if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to V_5_3 once backported
if (in.getVersion().before(Version.V_5_3_0)) {
// we do not know the format from earlier versions so convert if necessary
source = XContentHelper.convertToJson(new BytesArray(source), false, false, XContentFactory.xContentType(source));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public void readFrom(StreamInput in) throws IOException {
for (int i = 0; i < size; i++) {
final String type = in.readString();
String mappingSource = in.readString();
if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to V_5_3_0 once backported
if (in.getVersion().before(Version.V_5_3_0)) {
// we do not know the incoming type so convert it if needed
mappingSource =
XContentHelper.convertToJson(new BytesArray(mappingSource), false, false, XContentFactory.xContentType(mappingSource));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,19 @@ public void testPutMappingRequestSerialization() throws IOException {
request.source(mapping, XContentType.YAML);
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.source());

BytesStreamOutput bytesStreamOutput = new BytesStreamOutput();
request.writeTo(bytesStreamOutput);
StreamInput in = StreamInput.wrap(bytesStreamOutput.bytes().toBytesRef().bytes);
PutMappingRequest serialized = new PutMappingRequest();
serialized.readFrom(in);
final Version version = randomFrom(Version.CURRENT, Version.V_5_3_0, Version.V_5_3_1, Version.V_5_3_2, Version.V_5_4_0);
try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()) {
bytesStreamOutput.setVersion(version);
request.writeTo(bytesStreamOutput);
try (StreamInput in = StreamInput.wrap(bytesStreamOutput.bytes().toBytesRef().bytes)) {
in.setVersion(version);
PutMappingRequest serialized = new PutMappingRequest();
serialized.readFrom(in);

String source = serialized.source();
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), source);
String source = serialized.source();
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), source);
}
}
}

public void testSerializationBwc() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ public void testPutIndexTemplateRequestSerializationXContent() throws IOExceptio
assertNotEquals(mapping, request.mappings().get("bar"));
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.mappings().get("bar"));

BytesStreamOutput out = new BytesStreamOutput();
request.writeTo(out);
final Version version = randomFrom(Version.CURRENT, Version.V_5_3_0, Version.V_5_3_1, Version.V_5_3_2, Version.V_5_4_0);
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
request.writeTo(out);

StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
PutIndexTemplateRequest serialized = new PutIndexTemplateRequest();
serialized.readFrom(in);
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), serialized.mappings().get("bar"));
try (StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes)) {
in.setVersion(version);
PutIndexTemplateRequest serialized = new PutIndexTemplateRequest();
serialized.readFrom(in);
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML),
serialized.mappings().get("bar"));
}
}
}

public void testPutIndexTemplateRequestSerializationXContentBwc() throws IOException {
Expand Down