[committed] Quaternion not serializable with XMLEncoder unlike Vector3f

Hi!



com.jme.math.Quaternion has no read and write accessors unlike Vector3f, it is not homogeneous and it prevents from using Java build-in XML serialization on it (there is no error but the values of x, y, z and w are not encoded).



I only add 8 accessors:


public float getX() {
        return x;
    }

    public void setX(float x) {
        this.x = x;
    }

    public float getY() {
        return y;
    }

    public void setY(float y) {
        this.y = y;
    }

    public float getZ() {
        return z;
    }

    public void setZ(float z) {
        this.z = z;
    }

    public float getW() {
        return w;
    }

    public void setW(float w) {
        this.w = w;
    }

the fields are public, can you not access them directly ?

Core-Dump said:

the fields are public, can you not access them directly ?

I can access directly in my own code but the Java build-in XML serialization cannot do it because it follows the convention of Java Beans, it tries to get the value of x by using getX() even though x is public, that's the problem when you use the source code below:


String filename="myFile.xml";
BufferedOutputStream bos=null;
        File file=new File(filename);  
        try{if(!file.exists())
                if(!file.createNewFile())
                    throw new IOException("Unable to create the file "+filename);
            bos=new BufferedOutputStream(new FileOutputStream(file));
            XMLEncoder encoder=new XMLEncoder(bos);
            encoder.writeObject(new Quaternion(0.65328145f,-0.27059805f,-0.27059808f,0.6532815f));
            encoder.close();
           }
        catch(IOException ioe)
        {throw new RuntimeException("Unable to encode the file "+filename,ioe);}
        finally
        {if(bos!=null)
             try{bos.close();}
             catch(IOException ioe)
             {throw new RuntimeException("Unable to close the file "+filename,ioe);}



you get this (without my fix):

<void property="rotation">
       <object class="com.jme.math.Quaternion" />
</void>



you get this with my fix:

<void property="rotation">
       <object class="com.jme.math.Quaternion">
        <void property="w">
         <float>0.6532815</float>
        </void>
        <void property="x">
         <float>0.65328145</float>
        </void>
        <void property="y">
         <float>-0.27059805</float>
        </void>
        <void property="z">
         <float>-0.27059808</float>
        </void>



I submit my fix tomorrow if you don't see any objection.

Commited