ConfigurationConverter implements Converter { @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { DefaultConfiguration configuration = new DefaultConfiguration(); Map<String, Object> requiredArguments = new HashMap<String, Object>(); while(reader.hasMoreChildren()) { reader.moveDown(); if(metadata.xmlRequiredArgumentElement.equals(reader.getNodeName())) { requiredArguments.put(reader.getAttribute(metadata.xmlRequiredArgumentAttributeName), reader.getAttribute(metadata.xmlRequiredArgumentAttributeValue)); } reader.moveUp(); } configuration.setRequiredArguments(requiredArguments); log.trace("Created {}", configuration); return configuration; } ConfigurationConverter(Metadata metadata); @Override boolean canConvert(@SuppressWarnings("rawtypes") Class type); @Override void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context); @Override Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context);  }
@Test public void testUnmarshal() { DefaultConfiguration result = (DefaultConfiguration) xstream .fromXML("<configuration>" + "<requiredArgument name=\"arg1\" value=\"val1\"/>" + "<requiredArgument name=\"arg2\" value=\"val2\"/>" + "</configuration>"); assertNotNull(result); assertNotNull(result.requiredArguments()); assertEquals("val1", result.requiredArguments().get("arg1")); assertEquals("val2", result.requiredArguments().get("arg2")); }