KeyValueSerializer implements DataModelObjectSerializer { @Override public Collection<KeyValuePair> serialize(final DataModel model, final String name, final Object value) throws SemanticError { final Collection<KeyValuePair> pairs = new java.util.ArrayList<KeyValuePair>(); if (value instanceof Scriptable) { final Scriptable scriptable = (Scriptable) value; serialize(scriptable, name, pairs); } else { final KeyValuePair pair; if (value == null) { pair = new KeyValuePair(name, ""); } else { pair = new KeyValuePair(name, value.toString()); } pairs.add(pair); } return pairs; }  @Override Collection<KeyValuePair> serialize(final DataModel model,
            final String name, final Object value);  }
@Test public void testSerialize() throws JVoiceXMLEvent { final DataModel model = new EcmaScriptDataModel(); model.createScope(Scope.SESSION); model.evaluateExpression("var A = new Object();", Object.class); model.evaluateExpression("A.B = 'test';", Object.class); model.evaluateExpression("A.C = new Object();", Object.class); model.evaluateExpression("A.C.D = 42.0;", Object.class); model.evaluateExpression("A.C.E = null;", Object.class); final DataModelObjectSerializer serializer = new KeyValueSerializer(); final Object object = model.readVariable("A", Object.class); final Collection<KeyValuePair> pairs = serializer.serialize(model, "A", object); Assert.assertEquals(2, pairs.size()); final Iterator<KeyValuePair> iterator = pairs.iterator(); final KeyValuePair pair1 = iterator.next(); Assert.assertEquals("A.B", pair1.getKey()); Assert.assertEquals("test", pair1.getValue()); final KeyValuePair pair2 = iterator.next(); Assert.assertEquals("A.C.D", pair2.getKey()); Assert.assertEquals("42", pair2.getValue()); }