}
@Test
public void testMetadataToDelete() throws Exception {
Record record = repository.getRecordFactory().newRecord();
record.setMetadata(new QName("ns", "field1"),
new MetadataBuilder()
.value("mfield1", "value1")
.delete("mfield2")
.delete("mfield3")
.build());
record.setMetadata(new QName("ns", "field2"),
new MetadataBuilder()
.delete("mfield4")
.build());
WriteOptions options = new WriteOptions();
options.setUseNamespacePrefixes(false);
ObjectNode recordNode = RecordWriter.INSTANCE.toJson(record, options, repository);
// Go through ser/deser
String recordJson = JsonFormat.serializeAsString(recordNode);
recordNode = (ObjectNode)JsonFormat.deserializeNonStd(recordJson);
assertNotNull(recordNode.get("metadataToDelete"));
assertEquals(2, recordNode.get("metadataToDelete").size());
assertEquals(2, recordNode.get("metadataToDelete").get("{ns}field1").size());
assertEquals(1, recordNode.get("metadataToDelete").get("{ns}field2").size());
// Now parse json again to API objects
record = RecordReader.INSTANCE.fromJson(recordNode, repository);
assertEquals(2, record.getMetadataMap().size());
Metadata metadata = record.getMetadata(new QName("ns", "field1"));
assertTrue(metadata.getFieldsToDelete().contains("mfield2"));
assertTrue(metadata.getFieldsToDelete().contains("mfield3"));
assertEquals("value1", metadata.get("mfield1"));
metadata = record.getMetadata(new QName("ns", "field2"));
assertTrue(metadata.getFieldsToDelete().contains("mfield4"));
assertEquals(1, metadata.getFieldsToDelete().size());
}