[xstream-user] BufferedImage Converter

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

[xstream-user] BufferedImage Converter

Kacper Grubalski
Hello!

I wrote a converter for the type java.awt.BufferedImage. I registered it and put
some println's for the current type in the canConvert method. I start to
serialize and the method is called a few times, but it did not print the type
BufferedImage wich realy exists as a public field in my class. Of course i
expect a message (exception) that says BufferedImage could not be serialized or
something like that, but nothing happens. XStream skips this field, says nothing
and I dont know why. It serializes all the other fields and after deserializing
I have all values restored, except for this one.

Kacper

Reply | Threaded
Open this post in threaded view
|

[xstream-user] Re: BufferedImage Converter

Jörg Schaible-2
Hi Kacper,

Kacper Grubalski wrote:

> Hello!
>
> I wrote a converter for the type java.awt.BufferedImage. I registered it
> and put some println's for the current type in the canConvert method. I
> start to serialize and the method is called a few times, but it did not
> print the type BufferedImage wich realy exists as a public field in my
> class. Of course i expect a message (exception) that says BufferedImage
> could not be serialized or something like that, but nothing happens.
> XStream skips this field, says nothing and I dont know why. It serializes
> all the other fields and after deserializing I have all values restored,
> except for this one.
>
> Kacper

please show the code of your converter.

- J?rg

Reply | Threaded
Open this post in threaded view
|

Re: [xstream-user] BufferedImage Converter

Joe Walnes-2
In reply to this post by Kacper Grubalski
On 11/14/05, Kacper Grubalski <[hidden email]> wrote:
> I wrote a converter for the type java.awt.BufferedImage. I registered it and put
> some println's for the current type in the canConvert method. I start to
> serialize and the method is called a few times, but it did not print the type
> BufferedImage wich realy exists as a public field in my class.

If this public field is either null or marked as transient, XStream
will not try and serialize it.

-Joe
Reply | Threaded
Open this post in threaded view
|

[xstream-user] Error on parsing "&.../"

Door.Xiao
Hi, All
I met a problem if I use "&.../" as the value in the XML inputing file. And I will get the below exception when I call fromXML(...) method to get the object from the special XML file using "&.../".
 
ConversionException:  : entity reference name can not contain character /' (position: TEXT seen ...om.xstream.acceptance.objects.SampleLists" infile="E:/project/p&g/... @3:104)
---- Debugging information ----
required-type       : java.util.ArrayList
cause-message       :  : entity reference name can not contain character /' (position: TEXT seen ...om.xstream.acceptance.objects.SampleLists" infile="E:/project/p&g/... @3:104) 
class               : com.achievo.sxs.util.Configuration
message             :  : entity reference name can not contain character /' (position: TEXT seen ...om.xstream.acceptance.objects.SampleLists" infile="E:/project/p&g/... @3:104) 
line number         : 3
path                : /XStream-Config/objects
cause-exception     : StreamException
 
The below is the XML inputing file:
<XStream-Config>
  <objects>
    <object name="lists" classname="com.xstream.acceptance.objects.SampleLists" infile="E:\project\p&g\XStream\src\java\testSrc.xml" outfile="E:\project\p&g\XStream\src\java\testDest.xml">
      <attrs>
        <attr inalias="software" classname="com.xstream.acceptance.objects.Software" outalias="software"/>
        <attr inalias="hardware" classname="com.xstream.acceptance.objects.Hardware" outalias="hardware"/>
      </attrs>
    </object>
  </objects>
</XStream-Config>
 
Although I can take other filepath to avoid this problem, but how can I do if I stick to this usage? Thanks a lot.
 
Regards,
Door.Xiao
Reply | Threaded
Open this post in threaded view
|

RE: [xstream-user] Error on parsing "&.../"

Jörg Schaible
Door.Xiao wrote on Tuesday, November 15, 2005 10:36 AM:

> Hi, All
> I met a problem if I use "&.../" as the value in the XML inputing
> file. And I will get the below exception when I call fromXML(...)
> method to get the object from the special XML file using "&.../".  

How did you create the XML? With XStream? '&' starts an entitiy definition and the error is from the underlaying XML parser.

- Jörg
Reply | Threaded
Open this post in threaded view
|

Re: [xstream-user] Error on parsing "&.../"

Door.Xiao

Hi, Jörg
Thanks for your quick answer.
Yes. This exception is from the XPP parser. And I manually create this XML file as a config file. I just want to read the data into a created class named "Configuration" from the XML file. And "E:\project\test\SmartXMLStream\testSrc.xml" just is the value of one attribute in the XML file.
Maybe I should consult Aleksander Slominski  (the author of MXP1)? Thanks again.
 
Regards,
Door.Xiao
 
----- Original Message -----
From: "Jörg Schaible" <[hidden email]>
Sent: Tuesday, November 15, 2005 5:41 PM
Subject: RE: [xstream-user] Error on parsing "&.../"

Door.Xiao wrote on Tuesday, November 15, 2005 10:36 AM:

> Hi, All
> I met a problem if I use "&.../" as the value in the XML inputing
> file. And I will get the below exception when I call fromXML(...)
> method to get the object from the special XML file using "&.../". 

How did you create the XML? With XStream? '&' starts an entitiy definition and the error is from the underlaying XML parser.

- Jörg
Reply | Threaded
Open this post in threaded view
|

RE: [xstream-user] Error on parsing "&.../"

Jörg Schaible
In reply to this post by Door.Xiao
Door.Xiao wrote on Tuesday, November 15, 2005 11:01 AM:

> Hi, Jörg
> Thanks for your quick answer.
> Yes. This exception is from the XPP parser. And I manually create
> this XML file as a config file. I just want to read the data into a
> created class named "Configuration" from the XML file. And
> "E:\project\test\SmartXMLStream\testSrc.xml" just is the value of one
> attribute in the XML file. Maybe I should consult Aleksander
> Slominski  (the author of MXP1)? Thanks again.    

No, *every* XML parser *has to* fail here, because you don't deliver valid input. To place an ampersand into the String you have to defin this character itself as entity: &amp;

- Jörg
Reply | Threaded
Open this post in threaded view
|

Re: [xstream-user] Error on parsing "&.../"

Door.Xiao
Hi, J�rg
How can I do to define the ampersand as entity: &amp? Thank you very much.

Regards,
Door.Xiao

----- Original Message -----
From: "J�rg Schaible" <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, November 15, 2005 6:07 PM
Subject: RE: [xstream-user] Error on parsing "&.../"


Door.Xiao wrote on Tuesday, November 15, 2005 11:01 AM:

> Hi, J�rg
> Thanks for your quick answer.
> Yes. This exception is from the XPP parser. And I manually create
> this XML file as a config file. I just want to read the data into a
> created class named "Configuration" from the XML file. And
> "E:\project\test\SmartXMLStream\testSrc.xml" just is the value of one
> attribute in the XML file. Maybe I should consult Aleksander
> Slominski  (the author of MXP1)? Thanks again.

No, *every* XML parser *has to* fail here, because you don't deliver valid
input. To place an ampersand into the String you have to defin this
character itself as entity: &amp;

- J�rg

Reply | Threaded
Open this post in threaded view
|

RE: [xstream-user] Error on parsing "&.../"

Jörg Schaible
In reply to this post by Door.Xiao
Hi,

Door.Xiao wrote on Tuesday, November 15, 2005 11:52 AM:

> Hi, Jörg
> How can I do to define the ampersand as entity: &amp? Thank
> you very much.

well, you provide the content for the XML parser manually, so it is your task to provide it in a way it is understandable. If the XML parser has to deliver an ampersand, you must feed it with the entitiy "&amp;". See XML specs. XStream is not even involved here.

- Jörg
Reply | Threaded
Open this post in threaded view
|

Re: [xstream-user] Error on parsing "&.../"

Door.Xiao
Hi, J�rg,
Yes. You are right. Thank you very much. Also I get it by reading these two
methods PrettyPrintWriter.writeAttributeValue() and
MXParser.parseEntityRef().

Best Regards.
Door.Xiao



----- Original Message -----
From: "J�rg Schaible" <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, November 15, 2005 8:21 PM
Subject: RE: [xstream-user] Error on parsing "&.../"


Hi,

Door.Xiao wrote on Tuesday, November 15, 2005 11:52 AM:

> Hi, J�rg
> How can I do to define the ampersand as entity: &amp? Thank
> you very much.

well, you provide the content for the XML parser manually, so it is your
task to provide it in a way it is understandable. If the XML parser has to
deliver an ampersand, you must feed it with the entitiy "&amp;". See XML
specs. XStream is not even involved here.

- J�rg

Reply | Threaded
Open this post in threaded view
|

[xstream-user] Extensibility on deserialization with "value="

Door.Xiao
In reply to this post by Jörg Schaible

Hi, Jörg,
After I read Holger's mail again. I think there is a new requirement that improve the XStream's extensibility such as add the other outputing format.
For example, Sometime I need the below XML format(1):
<lists>
  <good>
    <hardware>
      <arch>Huawei</arch>
      <name>Renzhengfei</name>
    </hardware>
  </good>
  <bad class="list">
    <software>
      <vendor>Achievo</vendor>
      <name>Raymond</name>
    </software>
  </bad>
</lists>
And sometime I think the below format(2) is better for me:
<lists>
  <good>
    <hardware>
      <arch value="Huawei>
      <name value="Renzhengfei">
    </hardware>
  </good>
  <bad class="list">
    <software>
      <vendor value="Achievo">
      <name value="Raymond">
    </software>
  </bad>
</lists>
I remember you pointed out in the reply for Holger's mail: User can create a separate converter and register it into XStream to parse this object. But I think it is more suitable if XStream can provide a format-factory which can generate the format(1) and also can generate format(2). Whether can we do it now through modifing the ReflectionConverter class? (Just my thought)  You are familiar with the framework and the souce code of XStream. How about my idea? Thanks a lot.
 
Regards,
Door.Xiao
 
 
Reply | Threaded
Open this post in threaded view
|

RE: [xstream-user] Extensibility on deserialization with "value="

Jörg Schaible
Hi Doo.Xiao,

Door.Xiao wrote on Tuesday, November 15, 2005 2:37 PM:

> Hi, Jörg,
> After I read Holger's mail again. I think there is a new requirement
> that improve the XStream's extensibility such as add the other
> outputing format.  

[snip]

> I remember you pointed out in the reply for Holger's mail: User can
> create a separate converter and register it into XStream to parse
> this object. But I think it is more suitable if XStream can provide a
> format-factory which can generate the format(1) and also can generate
> format(2). Whether can we do it now through modifing the
> ReflectionConverter class? (Just my thought)  You are familiar with
> the framework and the souce code of XStream. How about my idea?
> Thanks a lot.      

Unfortunately you cannot simply generalize it. In this case XStream should have to know, wether the original converter for the object generates a String representation for the marshalling or not and it could also not save/restore references to the same objects. This qualifies the use case as an example in a howto, but not as a general available alternative to marshal and unmarshal an object tree. Additionally where do you want to draw the line? In your case you created no attributes named "value", but you implemented a container object with attributes named after your "properties" ... and you also did so for the properties/members that had a streamable string representation (also silently dropping references to same objects), but not for your list member. Both use cases would have been solvable with an XML transformation too (with more overhead naturally). XStream is in first place a library to marshal and unmarshal (recognize the sequence) objects fast to/from XML, that can be adjusted to individual needs due to its flexible design.

- Jörg
Reply | Threaded
Open this post in threaded view
|

Re: [xstream-user] Extensibility on deserialization with "value="

sebb-2-2
On 15/11/05, Jörg Schaible <[hidden email]> wrote:

> Hi Doo.Xiao,
>
> Door.Xiao wrote on Tuesday, November 15, 2005 2:37 PM:
>
> > Hi, Jörg,
> > After I read Holger's mail again. I think there is a new requirement
> > that improve the XStream's extensibility such as add the other
> > outputing format.
>
> [snip]
>
> > I remember you pointed out in the reply for Holger's mail: User can
> > create a separate converter and register it into XStream to parse
> > this object. But I think it is more suitable if XStream can provide a
> > format-factory which can generate the format(1) and also can generate
> > format(2). Whether can we do it now through modifing the
> > ReflectionConverter class? (Just my thought)  You are familiar with
> > the framework and the souce code of XStream. How about my idea?
> > Thanks a lot.
>
> Unfortunately you cannot simply generalize it. In this case XStream should have to know, wether the original converter for the object generates a String representation for the marshalling or not and it could also not save/restore references to the same objects. This qualifies the use case as an example in a howto, but not as a general available alternative to marshal and unmarshal an object tree. Additionally where do you want to draw the line? In your case you created no attributes named "value", but you implemented a container object with attributes named after your "properties" ... and you also did so for the properties/members that had a streamable string representation (also silently dropping references to same objects), but not for your list member. Both use cases would have been solvable with an XML transformation too (with more overhead naturally). XStream is in first place a library to marshal and unmarshal (recognize the sequence) objects fast to/from XML, that can be adjusted to individual needs due to its flexible design.
>

But perhaps XStream could have a means of telling the Converters which
fields are to be saved as attributes rather than nested tags?
Reply | Threaded
Open this post in threaded view
|

Re: [xstream-user] Extensibility on deserialization with "value="

Door.Xiao
Yes. I just want to convert these immutable type(simple data type) fields as
attribute and where not exist the same object to save/restore as reference.

Regards,
Door.Xiao

----- Original Message -----
From: "sebb" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, November 16, 2005 2:07 AM
Subject: Re: [xstream-user] Extensibility on deserialization with "value="


On 15/11/05, J�rg Schaible <[hidden email]> wrote:

> Hi Doo.Xiao,
>
> Door.Xiao wrote on Tuesday, November 15, 2005 2:37 PM:
>
> > Hi, J�rg,
> > After I read Holger's mail again. I think there is a new requirement
> > that improve the XStream's extensibility such as add the other
> > outputing format.
>
> [snip]
>
> > I remember you pointed out in the reply for Holger's mail: User can
> > create a separate converter and register it into XStream to parse
> > this object. But I think it is more suitable if XStream can provide a
> > format-factory which can generate the format(1) and also can generate
> > format(2). Whether can we do it now through modifing the
> > ReflectionConverter class? (Just my thought)  You are familiar with
> > the framework and the souce code of XStream. How about my idea?
> > Thanks a lot.
>
> Unfortunately you cannot simply generalize it. In this case XStream should
> have to know, wether the original converter for the object generates a
> String representation for the marshalling or not and it could also not
> save/restore references to the same objects. This qualifies the use case
> as an example in a howto, but not as a general available alternative to
> marshal and unmarshal an object tree. Additionally where do you want to
> draw the line? In your case you created no attributes named "value", but
> you implemented a container object with attributes named after your
> "properties" ... and you also did so for the properties/members that had a
> streamable string representation (also silently dropping references to
> same objects), but not for your list member. Both use cases would have
> been solvable with an XML transformation too (with more overhead
> naturally). XStream is in first place a library to marshal and unmarshal
> (recognize the sequence) objects fast to/from XML, that can be adjusted to
> individual needs due to its flexible design.
>

But perhaps XStream could have a means of telling the Converters which
fields are to be saved as attributes rather than nested tags?