private void writeList(OutputCapsule oc, Collection<?> list, String listName) throws IOException {
        if (list != null) {
            oc.write(list.size(), listName + "size", 0);
            int counter = 0;
            for (Object o : list) {
                // t is for 'type'; v is for 'value'
                if (o instanceof Integer) {
                    oc.write(TYPE_INTEGER, listName + "t" + counter, 0);
                    oc.write((Integer) o, listName + "v" + counter, 0);
                } else if (o instanceof Float) {
                    oc.write(TYPE_FLOAT, listName + "t" + counter, 0);
                    oc.write((Float) o, listName + "v" + counter, 0f);
                } else if (o instanceof Boolean) {
                    oc.write(TYPE_BOOLEAN, listName + "t" + counter, 0);
                    oc.write((Boolean) o, listName + "v" + counter, false);
                } else if (o instanceof String || o == null) {// treat nulls like Strings just to store them and keep the List like the user intended
                    oc.write(TYPE_STRING, listName + "t" + counter, 0);
                    oc.write((String) o, listName + "v" + counter, null);
                } else if (o instanceof Long) {
                    oc.write(TYPE_LONG, listName + "t" + counter, 0);
                    oc.write((Long) o, listName + "v" + counter, 0L);
                } else if (o instanceof Savable) {
                    oc.write(TYPE_SAVABLE, listName + "t" + counter, 0);
                    oc.write((Savable) o, listName + "v" + counter, null);
                } else if(o instanceof Object[]) {
                    oc.write(TYPE_ARRAY, listName + "t" + counter, 0);
                    this.writeList(oc, Arrays.asList((Object[]) o), listName + "v" + counter);
                } else if(o instanceof List) {
                    oc.write(TYPE_LIST, listName + "t" + counter, 0);
                    this.writeList(oc, (List<?>) o, listName + "v" + counter);
                } else if(o instanceof Map) {
                    oc.write(TYPE_MAP, listName + "t" + counter, 0);
                    Map<?, ?> map = (Map<?, ?>) o;
                    this.writeList(oc, map.keySet(), listName + "v(keys)" + counter);
                    this.writeList(oc, map.values(), listName + "v(vals)" + counter);
                } else if (o instanceof Double) {
                    oc.write(TYPE_DOUBLE, listName + "t" + counter, 0);
                    oc.write((Double) o, listName + "v" + counter, 0.);
                } else if (o instanceof Short) {
                    oc.write(TYPE_SHORT, listName + "t" + counter, 0);
                    oc.write((Short) o, listName + "v" + counter, (short)0);
                } else if (o instanceof Byte) {
                    oc.write(TYPE_BYTE, listName + "t" + counter, 0);
                    oc.write((Byte) o, listName + "v" + counter, (byte)0);
                } else {
                    throw new UnsupportedOperationException("Unsupported type stored in the list: " + o.getClass());
                }
                
                ++counter;
            }
        } else {
            oc.write(0, "size", 0);
        }
    }
The method stores a list in the capsule.
@param oc
           output capsule
@param list
           the list to be stored
@throws IOException
           from the capsule
jme3-core/src/main/java/com/jme3/scene/UserData.java