@Override
    public void write(JmeExporter ex) throws IOException {
        OutputCapsule oc = ex.getCapsule(this);
        oc.write(type, "type", (byte) 0);
        
        switch (type) {
            case TYPE_INTEGER:
                int i = (Integer) value;
                oc.write(i, "intVal", 0);
                break;
            case TYPE_FLOAT:
                float f = (Float) value;
                oc.write(f, "floatVal", 0f);
                break;
            case TYPE_BOOLEAN:
                boolean b = (Boolean) value;
                oc.write(b, "boolVal", false);
                break;
            case TYPE_STRING:
                String s = (String) value;
                oc.write(s, "strVal", null);
                break;
            case TYPE_LONG:
                Long l = (Long) value;
                oc.write(l, "longVal", 0l);
                break;
            case TYPE_SAVABLE:
                Savable sav = (Savable) value;
                oc.write(sav, "savableVal", null);
                break;
            case TYPE_LIST:
                this.writeList(oc, (List<?>) value, "0");
                break;
            case TYPE_MAP:
                Map<?, ?> map = (Map<?, ?>) value;
                this.writeList(oc, map.keySet(), "0");
                this.writeList(oc, map.values(), "1");
                break;
            case TYPE_ARRAY:
                this.writeList(oc, Arrays.asList((Object[]) value), "0");
                break;
            case TYPE_DOUBLE:
                Double d = (Double) value;
                oc.write(d, "doubleVal", 0.);
                break;
            case TYPE_SHORT:
                Short sh = (Short) value;
                oc.write(sh, "shortVal", (short)0);
                break;
            case TYPE_BYTE:
                Byte bh = (Byte) value;
                oc.write(bh, "byteVal", (byte)0);
                break;
            default:
                throw new UnsupportedOperationException("Unsupported value type: " + value.getClass());
        }
    }
Creates a new <code>UserData</code> with the given
type and value.

@param type
           Type of data, should be between 0 and 8.
@param value
           Value of the data
jme3-core/src/main/java/com/jme3/scene/UserData.java