XmlSettingsReader { public <T> T getComplexType(String tagName, Class<T> targetClass) { Node property = getElement(doc, tagName); if (property == null) { return null; } try { JAXBContext jc = JAXBContext.newInstance(targetClass); Unmarshaller unmarshaller = jc.createUnmarshaller(); JAXBElement<T> jb = unmarshaller.unmarshal(property, targetClass); return jb.getValue(); } catch (JAXBException e) { throw new IllegalArgumentException( "Problem extracting " + targetClass + " from settings: " + e.getMessage()); } } XmlSettingsReader(String xmlString); int getIntProperty(String xPathExp, String tagName, int defaultVal); String getStringPropertyByXPath(String xPathExp, String tagName); String getStringPropertyByXPath(String xPathExp, String tagName, String defaultVal); boolean getBooleanProperty(String xPathExp, String tagName, boolean defaultVal); String getStringProperty(String tagName); File getFileProperty(String tagName); String getStringProperty(String tagName, String defaultValue); List<String> getStringListProperty(String tagName); Map<String, Boolean> getStringKeyedBooleanMapProperty(String tagName); Map<String, T> getStringKeyedMapProperty(String tagName, Function<String, T> mapFunction); T getComplexType(String tagName, Class<T> targetClass);  }
@Test public void readComplexTypeProperty() throws Exception { String complexXml = prepareElement(COMPLEX_TAG, String.valueOf(booleanValue)); xsr = new XmlSettingsReader(complexXml); Boolean readComplexProperty = xsr.getComplexType(COMPLEX_TAG, Boolean.class); assertEquals(booleanValue, readComplexProperty); }