Bar bar2 = new Bar();
bar2.restrictedBarProperty = 11;
foo.bars = new Bar[] { bar1, bar2 };
ObjectMapper xmlMapper = new XmlMapper();
xmlMapper.configure(MapperFeature.AUTO_DETECT_FIELDS, false );
xmlMapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false );
xmlMapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false );
xmlMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false );
String xml = xmlMapper.writerWithView(RestrictedView.class).writeValueAsString(foo);
// views not used for deserialization
Foo result = xmlMapper.readValue(xml, Foo.class);
assertEquals("test", result.restrictedFooProperty);
assertNotNull(result.bars);
assertEquals(2, result.bars.length);
assertEquals(10, result.bars[0].restrictedBarProperty);
assertEquals(11, result.bars[1].restrictedBarProperty);