Hi Edison,
You can customize the JSX serialization of the class using the
standard techniques as for JOS (Java Object Serialization). See below.
But first, let me ask something:
How much shorter do you need it to be? The JSX output truly is
verbose; but even if shorter, XML is still pretty verbose:
(1). Would zipping the XML help enough? Due to the redundancy of
JSX's XML, it compresses very well.
(2). If you have an "image file", is there any way to just save that
file (eg in a DB, or in the filesystem), and refer to it from the XML,
instead of serializing as XML what is already a serial format? (I
recognize there can be good reasons for not doing this)
Customizing JSX:
For example, you could create a string that represents the image (in
base64, or whatever you want), and record that as the serial form (and
the decoder to read this back). Here's two ways of making JSX use your
code:
If the class is your own (ie you can edit it), you do this by writing
writeObject() and readObject() methods in your class - these are
call-back methods that JSX will call in your class.
If the class is not your own (ie you can't edit it), you can subclass
JSX.ObjectWriter, and implement the "Object objectReplace(Object obj)"
method: in it, you detect if the object is of the class in question,
and if it is, construct a new object, which has a field initialized to
the String you want (as above). For reading, you subclass
JSX.ObjectReader, and implement "Object resolveObject(Object obj)" etc
There are lots of resources available for how to do this. There's the
JSX manual on www.jsx.org/support.html
http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/output.html
http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/input.html
There are many tutorials online: search for JOS customization.
Please post to the mailing list how you are going, and any questions you have.
Hope this helps,
Brendan
On 26/03/2008, edison ouyang <edison728@...> wrote:
> Hi:
> I am using the trial version JSX to serialize and de-serialize the
> object.
> I serialized an image file, this is the output for the image:
> <primitive type='byte' value='-119'/>
> <primitive type='byte' value='80'/>
> <primitive type='byte' value='78'/>
> <primitive type='byte' value='71'/>
> <primitive type='byte' value='13'/>
> <primitive type='byte' value='10'/>
> <primitive type='byte' value='26'/>
> <primitive type='byte' value='10'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='13'/>
> <primitive type='byte' value='73'/>
> <primitive type='byte' value='72'/>
> <primitive type='byte' value='68'/>
> <primitive type='byte' value='82'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='-6'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='-6'/>
> <primitive type='byte' value='8'/>
> <primitive type='byte' value='6'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='-120'/>
> <primitive type='byte' value='-20'/>
> <primitive type='byte' value='90'/>
> <primitive type='byte' value='61'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='0'/>
> <primitive type='byte' value='5'/>
> ......................
>
> this method to keep the image in the xml makes the file quite big.
> Is it possible to customize the other encoding methods defined in the API
> such as using base 64 for image.
>
> Thanks for your time.
>
> edison
>
>
>
>
>
>
>
--
The competent programmer is fully aware of the strictly limited size
of his own skull; therefore he approaches the programming task in full
humility, and among other things he avoids clever tricks like the
plague. - Dijkstra
--
The competent programmer is fully aware of the strictly limited size
of his own skull; therefore he approaches the programming task in full
humility, and among other things he avoids clever tricks like the
plague. - Dijkstra