@Test public void unmarshal() throws Exception { ConfigProperties properties = new ConfigProperties(); JAXBElement<String> someElement = new JAXBElement<>(QName.valueOf("message"), String.class, "I love sparrows!!"); JAXBElement<String> someOtherElement = new JAXBElement<>(QName.valueOf("greeting"), String.class, "Hellow"); properties.setProperties(Arrays.asList(someElement, someOtherElement)); Map<String, String> result = adapter.unmarshal(properties); Map<String, String> map = new LinkedHashMap<>(); map.put("message", "I love sparrows!!"); map.put("greeting", "Hellow"); assertThat(result).containsAllEntriesOf(map); }
@Override public Map<String, String> unmarshal(ConfigProperties configProperties) throws Exception { if (configProperties == null) return null; Map<String, String> outcome = new LinkedHashMap<>(); for (Object element : configProperties.getProperties()) { if (Element.class.isInstance(element)) { String localname = Element.class.cast(element).getLocalName(); String value = Optional.ofNullable(element) .map(Element.class::cast) .map(Element::getFirstChild) .map(Node::getNodeValue) .orElse(null); outcome.put(localname, value); } if (JAXBElement.class.isInstance(element)) { String localname = JAXBElement.class.cast(element).getName().getLocalPart(); String value = Objects.toString(JAXBElement.class.cast(element).getValue()); outcome.put(localname, value); } } return outcome; }
MapAdapter extends XmlAdapter<ConfigProperties, Map<String, String>> { @Override public Map<String, String> unmarshal(ConfigProperties configProperties) throws Exception { if (configProperties == null) return null; Map<String, String> outcome = new LinkedHashMap<>(); for (Object element : configProperties.getProperties()) { if (Element.class.isInstance(element)) { String localname = Element.class.cast(element).getLocalName(); String value = Optional.ofNullable(element) .map(Element.class::cast) .map(Element::getFirstChild) .map(Node::getNodeValue) .orElse(null); outcome.put(localname, value); } if (JAXBElement.class.isInstance(element)) { String localname = JAXBElement.class.cast(element).getName().getLocalPart(); String value = Objects.toString(JAXBElement.class.cast(element).getValue()); outcome.put(localname, value); } } return outcome; } }
MapAdapter extends XmlAdapter<ConfigProperties, Map<String, String>> { @Override public Map<String, String> unmarshal(ConfigProperties configProperties) throws Exception { if (configProperties == null) return null; Map<String, String> outcome = new LinkedHashMap<>(); for (Object element : configProperties.getProperties()) { if (Element.class.isInstance(element)) { String localname = Element.class.cast(element).getLocalName(); String value = Optional.ofNullable(element) .map(Element.class::cast) .map(Element::getFirstChild) .map(Node::getNodeValue) .orElse(null); outcome.put(localname, value); } if (JAXBElement.class.isInstance(element)) { String localname = JAXBElement.class.cast(element).getName().getLocalPart(); String value = Objects.toString(JAXBElement.class.cast(element).getValue()); outcome.put(localname, value); } } return outcome; }  }
MapAdapter extends XmlAdapter<ConfigProperties, Map<String, String>> { @Override public Map<String, String> unmarshal(ConfigProperties configProperties) throws Exception { if (configProperties == null) return null; Map<String, String> outcome = new LinkedHashMap<>(); for (Object element : configProperties.getProperties()) { if (Element.class.isInstance(element)) { String localname = Element.class.cast(element).getLocalName(); String value = Optional.ofNullable(element) .map(Element.class::cast) .map(Element::getFirstChild) .map(Node::getNodeValue) .orElse(null); outcome.put(localname, value); } if (JAXBElement.class.isInstance(element)) { String localname = JAXBElement.class.cast(element).getName().getLocalPart(); String value = Objects.toString(JAXBElement.class.cast(element).getValue()); outcome.put(localname, value); } } return outcome; }  @Override Map<String, String> unmarshal(ConfigProperties configProperties); @Override ConfigProperties marshal(Map<String, String> map); }
MapAdapter extends XmlAdapter<ConfigProperties, Map<String, String>> { @Override public Map<String, String> unmarshal(ConfigProperties configProperties) throws Exception { if (configProperties == null) return null; Map<String, String> outcome = new LinkedHashMap<>(); for (Object element : configProperties.getProperties()) { if (Element.class.isInstance(element)) { String localname = Element.class.cast(element).getLocalName(); String value = Optional.ofNullable(element) .map(Element.class::cast) .map(Element::getFirstChild) .map(Node::getNodeValue) .orElse(null); outcome.put(localname, value); } if (JAXBElement.class.isInstance(element)) { String localname = JAXBElement.class.cast(element).getName().getLocalPart(); String value = Objects.toString(JAXBElement.class.cast(element).getValue()); outcome.put(localname, value); } } return outcome; }  @Override Map<String, String> unmarshal(ConfigProperties configProperties); @Override ConfigProperties marshal(Map<String, String> map);  }