class 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;
    }

}