You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Michael Gardner <ga...@gmail.com> on 2006/04/29 21:51:30 UTC

[betwixt] className for String, Integer?

I've un-suppressed the className attribute for all beans, but it doesn't
seem to get outputted for Strings and Integers (presumably because those are
handled specially, not being true beans). How can I get betwixt to use
className for these, too?

Mike Gardner

Re: [betwixt] className for String, Integer?

Posted by Mornak <dm...@gmail.com>.
Michael, I think you need to review your mappings. When I had this
kind of problems I made a workaround throught the mappings, without
creating any custom beanCreatorChain (althought it may be work)

If you send your beans and a XML of how they should be outputed I (or
anybody else) may help to resolve your particular problem

(Excuse me awful english, I am from Argentina)

Good luck!



On 5/1/06, robert burrell donkin <ro...@blueyonder.co.uk> wrote:
> On Mon, 2006-05-01 at 15:10 -0500, Michael Gardner wrote:
> > Robert, thanks for the quick response. I submitted a bug to Bugzilla (
> > http://issues.apache.org/bugzilla/show_bug.cgi?id=39460), though without a
> > unit test yet since I'm having trouble getting the Betwixt test harness
> > working.
>
> if you continue to have problems, check out the source from subversion
> and take a look at the test cases in there. betwixt is mavenised
> (http://maven.apache.org) so building is easy. if you use eclipse, maven
> will generate a basic project outline.
>
> > Anyway, my basic use case involves properties that have setters with formal
> > parameter type 'Object': if I try to write such a bean that happens to have
> > a String as the value of such a property, BeanWriter will not write the
> > className property even though I've un-suppressed the className property in
> > general. Then when a BeanReader tries to reconstruct the object, it creates
> > a plain Object instead of a String (this also happens with Integer, etc.).
>
> ok
>
> > I can create wrappers for those types to work around the problem, but it
> > really messes up my code -- especially since this issue affects more than
> > one of my bean types. I thought of modifying Betwixt to no longer treat
> > Strings, etc. as simple types, but would BeanWriter still know how to write
> > them to XML in that case?
>
> recognition of simple types is pluggable. you'd need to create custom
> mappings for Integer and String but that should be ok.
>
> read in again is actually more difficult due to the fact that Integer
> and String are not really beans. i don't have the time to supply any
> code samples right now but i'll try to set you on the right path...
>
> if you have flexibility over the xml format then the quickest and
> easiest way to make things work would be to output the value of the
> string or integer as an attribute. then use a new custom
> BeanCreationChain which knows how to create a string or integer with the
> correct value when called upon to create the object from the complex
> type.
>
> otherwise, you need to looking into creating a custom MappingAction
> which is more difficult.
>
> - robert
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


--

To Iterate is Human, to Recurse, Divine
 - James O. Coplien, Bell Labs

-------------------------------------
<EPI/> - Deploying ideas
-------------------------------------
Ing. Diego H. Mornacco
Desarrollador
Epidata Consulting
MaipĂș 521 1er piso Of. A
Ofi: 5031 0060 / 61
Cel: 15-5884-0040
www.epidataconsulting.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [betwixt] className for String, Integer?

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Mon, 2006-05-01 at 15:10 -0500, Michael Gardner wrote:
> Robert, thanks for the quick response. I submitted a bug to Bugzilla (
> http://issues.apache.org/bugzilla/show_bug.cgi?id=39460), though without a
> unit test yet since I'm having trouble getting the Betwixt test harness
> working.

if you continue to have problems, check out the source from subversion
and take a look at the test cases in there. betwixt is mavenised
(http://maven.apache.org) so building is easy. if you use eclipse, maven
will generate a basic project outline. 

> Anyway, my basic use case involves properties that have setters with formal
> parameter type 'Object': if I try to write such a bean that happens to have
> a String as the value of such a property, BeanWriter will not write the
> className property even though I've un-suppressed the className property in
> general. Then when a BeanReader tries to reconstruct the object, it creates
> a plain Object instead of a String (this also happens with Integer, etc.).

ok

> I can create wrappers for those types to work around the problem, but it
> really messes up my code -- especially since this issue affects more than
> one of my bean types. I thought of modifying Betwixt to no longer treat
> Strings, etc. as simple types, but would BeanWriter still know how to write
> them to XML in that case?

recognition of simple types is pluggable. you'd need to create custom
mappings for Integer and String but that should be ok.

read in again is actually more difficult due to the fact that Integer
and String are not really beans. i don't have the time to supply any
code samples right now but i'll try to set you on the right path...

if you have flexibility over the xml format then the quickest and
easiest way to make things work would be to output the value of the
string or integer as an attribute. then use a new custom
BeanCreationChain which knows how to create a string or integer with the
correct value when called upon to create the object from the complex
type.

otherwise, you need to looking into creating a custom MappingAction
which is more difficult.

- robert



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [betwixt] className for String, Integer?

Posted by Michael Gardner <ga...@gmail.com>.
Robert, thanks for the quick response. I submitted a bug to Bugzilla (
http://issues.apache.org/bugzilla/show_bug.cgi?id=39460), though without a
unit test yet since I'm having trouble getting the Betwixt test harness
working.

Anyway, my basic use case involves properties that have setters with formal
parameter type 'Object': if I try to write such a bean that happens to have
a String as the value of such a property, BeanWriter will not write the
className property even though I've un-suppressed the className property in
general. Then when a BeanReader tries to reconstruct the object, it creates
a plain Object instead of a String (this also happens with Integer, etc.).

I can create wrappers for those types to work around the problem, but it
really messes up my code -- especially since this issue affects more than
one of my bean types. I thought of modifying Betwixt to no longer treat
Strings, etc. as simple types, but would BeanWriter still know how to write
them to XML in that case?

-Mike

On 5/1/06, robert burrell donkin <ro...@blueyonder.co.uk>
wrote:
>
> On Sat, 2006-04-29 at 14:51 -0500, Michael Gardner wrote:
> > I've un-suppressed the className attribute for all beans, but it doesn't
> > seem to get outputted for Strings and Integers (presumably because those
> are
> > handled specially, not being true beans).
>
> yep: mapped to simple rather than complex xml types
>
> > How can I get betwixt to use className for these, too?
>
> a good question and i need some more information  :)
>
> could you describe a bit more about you particular use case?
>
> (it would be great if you could contribute a unit test demonstrating
> your use case for use in the code base: please use bugzilla since this
> list strips most attachments)
>

Re: [betwixt] className for String, Integer?

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Sat, 2006-04-29 at 14:51 -0500, Michael Gardner wrote:
> I've un-suppressed the className attribute for all beans, but it doesn't
> seem to get outputted for Strings and Integers (presumably because those are
> handled specially, not being true beans). 

yep: mapped to simple rather than complex xml types

> How can I get betwixt to use className for these, too?

a good question and i need some more information  :)

could you describe a bit more about you particular use case? 

(it would be great if you could contribute a unit test demonstrating
your use case for use in the code base: please use bugzilla since this
list strips most attachments)

- robert





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org