Not sure if this is the right spot for this but i have seen that a quaternion is not serializable. The serializer does not complain but the data is not written correctly.
If i try to serialize a quaternion to XML and loading it again it looses all info.
[java]
try (XMLEncoder encoder = new XMLEncoder(new FileOutputStream("./TestQuaternion.xml"))) {
encoder.writeObject(new Quaternion(1, 2, 3, 4));
} catch (FileNotFoundException ex) {
}
[/java]
Will result in:
[java]
<?xml version=“1.0” encoding=“UTF-8”?>
<java version=“1.7.0_10” class=“java.beans.XMLDecoder”>
<object class=“com.jme3.math.Quaternion”/>
</java>
[/java]
While it works perfectly with a Vector3f for example:
[java]
try (XMLEncoder encoder = new XMLEncoder(new FileOutputStream("./TestVector.xml"))) {
encoder.writeObject(new Vector3f(1, 2, 3));
} catch (FileNotFoundException ex) {
}
[/java]
Will result in:
[java]
<?xml version=“1.0” encoding=“UTF-8”?>
<java version=“1.7.0_10” class=“java.beans.XMLDecoder”>
<object class=“com.jme3.math.Vector3f” id=“Vector3f0”>
<void class=“com.jme3.math.Vector3f” method=“getField”>
<string>x</string>
<void method=“set”>
<object idref=“Vector3f0”/>
<float>1.0</float>
</void>
</void>
<void class=“com.jme3.math.Vector3f” method=“getField”>
<string>y</string>
<void method=“set”>
<object idref=“Vector3f0”/>
<float>2.0</float>
</void>
</void>
<void class=“com.jme3.math.Vector3f” method=“getField”>
<string>z</string>
<void method=“set”>
<object idref=“Vector3f0”/>
<float>3.0</float>
</void>
</void>
</object>
</java>
[/java]
correct its not, here’s a list of the standard serializables:
http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/networking/com/jme3/network/serializing/Serializer.java
I think pspeed said he was going to update this list at some point, with primitive enums, among others
@wezrule said:
correct its not, here's a list of the standard serializables:
http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/networking/com/jme3/network/serializing/Serializer.java
I think pspeed said he was going to update this list at some point, with primitive enums, among others
He’s not talking about SpiderMonkey… he’s talking about standard Java XML encoding which JME doesn’t use at all. JME has its’ own XML serialization tech built in.
oh oops ^^ my bad, didn’t read it properly
But wait Quaternion does implement java.io.Serializable ?
@Empire Phoenix said:
But wait Quaternion does implement java.io.Serializable ?
Yes, he doesn’t mean that kind of serializable either.
He is trying to save things to XML in a non-JME way despite the fact that JME already has XML support. So maybe he is saving his own stuff and doesn’t want to use the JME stuff.
Either way, I have no idea why Vector3f works and Quaternion doesn’t. I’ve have expected neither to work. It may just be accidental that Vector3f looks enough like a bean that it worked.
Yeah that looks like JavaBeans XML-stuffs. (http://docs.oracle.com/javase/6/docs/api/java/beans/XMLEncoder.html)
If, like pspeed says, you want to save your own classes to XML and do not want to use jME-XML handling you should look at JAXB instead http://docs.oracle.com/javase/tutorial/jaxb/intro/
I would suggest xstream, it works out of the box with jme, as it works field based and not pre introspection.
(Very, very off-JME but it’s really hurting us at work here, so:)
You always learn something new. We’re currently struggling with setting up a web service at work, and JAXB is giving us trouble because it doesn’t really handle cycles (i.e. backlinks), and we fear that we’ll have to roll our own Hibernate proxy elimination as well.
A quick scan of xstream on the WWW looks very interesting. Does anybody use it to power a webservice? In particular, I haven’t found a way to generate WSDL; I’m not sure whether that’s because that’s so simple that nobody cares to write about it, or whether xstream is never used in a WSDL-using webservice context.
<cite>@toolforger said:</cite>
(Very, very off-JME but it's really hurting us at work here, so:)
You always learn something new. We’re currently struggling with setting up a web service at work, and JAXB is giving us trouble because it doesn’t really handle cycles (i.e. backlinks), and we fear that we’ll have to roll our own Hibernate proxy elimination as well.
That makes no sense, XML is a tree structure, not any graph. No library can map a cyclic graph to XML. Are you talking about using XML IDRefs?
xstream is certainly able to do that logic with the refs, but it cannot do wsdl as far as i know.
@jmaasing of course it would have to be IDRefs. Or anything else with an equivalent functionality - the “nice” thing about XML is that it’s so many standards that you never know whether you have seen it all.
@Empire_Phoenix it’s a pity if it can’t do WSDL, but ah well thanks for the info.