JSONSerializer 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>(); final String str = model.toString(value); final KeyValuePair pair = new KeyValuePair(name, str); 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 JSONSerializer(); final Object object = model.readVariable("A", Object.class); final Collection<KeyValuePair> pairs = serializer.serialize(model, "A", object); Assert.assertEquals(1, pairs.size()); final Iterator<KeyValuePair> iterator = pairs.iterator(); final KeyValuePair pair = iterator.next(); Assert.assertEquals("A", pair.getKey()); Assert.assertEquals("{\"B\":\"test\",\"C\":{\"D\":42,\"E\":null}}", pair.getValue()); }