public static void trimRecordTemplate(RecordTemplate recordTemplate, MaskTree override, final boolean failOnMismatch)
  {
    trimRecordTemplate(recordTemplate.data(), recordTemplate.schema(), override, failOnMismatch);
  }
@Test
  public void testUnionDataMap() throws CloneNotSupportedException
  {
    UnionTest foo = new UnionTest();
    foo.setUnionEmpty(new UnionTest.UnionEmpty());

    UnionTest expected = foo.copy();
    ((DataMap) foo.getUnionEmpty().data()).put("foo", "bar");

    RestUtils.trimRecordTemplate(foo, false);
    Assert.assertEquals(foo, expected);

    // Primitive case
    foo = new UnionTest();
    UnionTest.UnionWithNull bar = new UnionTest.UnionWithNull();
    bar.setBoolean(true);
    foo.setUnionWithNull(bar);
    expected = foo.copy();

    ((DataMap)foo.getUnionWithNull().data()).put("foo", "bar");
    Assert.assertEquals(((DataMap) foo.getUnionWithNull().data()).size(), 2);
    RestUtils.trimRecordTemplate(foo, false);
    Assert.assertEquals(foo, expected);

    // Complex case
    foo = new UnionTest();
    bar = new UnionTest.UnionWithNull();
    bar.setMap(new LongMap());
    foo.setUnionWithNull(bar);
    expected = foo.copy();
    expected.getUnionWithNull().getMap().put("foo", 1L);

    foo.getUnionWithNull().getMap().data().put("foo", 1L);
    foo.data().put("foo", "bar");
    Assert.assertEquals(((DataMap) foo.getUnionWithNull().data()).size(), 1);
    RestUtils.trimRecordTemplate(foo, false);
    Assert.assertEquals(foo, expected);
  }