You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Josef Wagner <Jo...@web.de> on 2006/01/04 10:27:11 UTC

Converting Java Plain Objects (OJB) to XML

Hello Users,

 

I wan't to convert my ojb plain java classes to XML. I tried to do this with
betwixt. When I do this like in the example on the Homepage, betwixt
converts also the referenzed objects to xml. I only want, that betwixt
converts the primitives types (attributes like integer, string.) of the
current class and not the referenced objects. I haven't found a flag to
configure this yet.

 

Any idea?

 

Thanks a lot

 

Josef Wagner


AW: Converting Java Plain Objects (OJB) to XML

Posted by Josef Wagner <Jo...@web.de>.
Hello,

thanks a lot for your suggestion.

I also have found another way to do this:

beanWriter.getXMLIntrospector().getConfiguration().
  setPropertySuppressionStrategy(
    new PropertySuppressionStrategy() {
      public boolean suppressProperty(Class classContainingTheProperty,
        Class propertyType, String propertyName) {
          if (propertyType.equals(Integer.class) ||
            propertyType.equals(String.class) ||
            propertyType.getClass().equals(Long.class) || 
            propertyType.getClass().equals(Float.class) ||  
            propertyType.getClass().equals(BigDecimal.class) || 
            propertyType.equals(Timestamp.class)) {           
              return false;
         }
         return true;
      }
  });

This works also fine.

But know, I have another problem, when reading the XML-Stream

I do the following:
1. Writing different Beans in a Stream

beanWriter.write("myBean1", new MyBean1());
beanWriter.write("myBean2", new MyBean2());
beanWriter.write("myBean3", new MyBean3());

2. Reading the different Beans from the written stream

beanReader.registerBeanClass("myBean1", MyBean1.class);
MyBean1 myBean1 = (MyBean1) beanReader.parse(xmlReader);

beanReader.registerBeanClass("myBean2", MyBean2.class);
MyBean2 myBean2 = (MyBean2) beanReader.parse(xmlReader);

beanReader.registerBeanClass("myBean3", MyBean3.class);
MyBean3 myBean3 = (MyBean3) beanReader.parse(xmlReader);

This way ends in Exceptions. When I write an read only one Bean, all works
fine. Isn't it possible to have more Beans in the XML output?

My second problem is that at this time I haven't the information, which tipe
of Bean (MyBean1, MyBean2, MyBean3) comes as returnvalue, when starting
"beanReader.parse(xmlReader);"

Thanks a lot for help
Josef Wagner (Germany)



-----Ursprüngliche Nachricht-----
Von: dhmspam-betwixt@yahoo.com.ar [mailto:dhmspam-betwixt@yahoo.com.ar] 
Gesendet: Mittwoch, 4. Januar 2006 13:49
An: Jakarta Commons Users List
Betreff: Re: Converting Java Plain Objects (OJB) to XML

Hallo

(excuse my english, but I am an spanish speaker)

You should map each POJO in dot-betwixt file.
if you use the addDefaults tag, use the "hide" tag to
ignore the properties that you don't want to be
mapped.
If not, just map the properties that you want to be
writed

I hope that it helps

Bye!




 --- Josef Wagner <Jo...@web.de> escribió:

> Hello Users,
> 
>  
> 
> I wan't to convert my ojb plain java classes to XML.
> I tried to do this with
> betwixt. When I do this like in the example on the
> Homepage, betwixt
> converts also the referenzed objects to xml. I only
> want, that betwixt
> converts the primitives types (attributes like
> integer, string.) of the
> current class and not the referenced objects. I
> haven't found a flag to
> configure this yet.
> 
>  
> 
> Any idea?
> 
>  
> 
> Thanks a lot
> 
>  
> 
> Josef Wagner
> 
> 


Ing. Diego H. Mornacco
Epidata Consulting S.R.L. <EPI/>
www.epidataconsulting.com
Cel: 15-5884-0040


"K.I.S.S.: Keep It Simple, S...!"


    


    
        
___________________________________________________________ 
1GB gratis, Antivirus y Antispam 
Correo Yahoo!, el mejor correo web del mundo 
http://correo.yahoo.com.ar 


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



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


Re: Converting Java Plain Objects (OJB) to XML

Posted by dh...@yahoo.com.ar.
Hallo

(excuse my english, but I am an spanish speaker)

You should map each POJO in dot-betwixt file.
if you use the addDefaults tag, use the "hide" tag to
ignore the properties that you don't want to be
mapped.
If not, just map the properties that you want to be
writed

I hope that it helps

Bye!




 --- Josef Wagner <Jo...@web.de> escribió:

> Hello Users,
> 
>  
> 
> I wan't to convert my ojb plain java classes to XML.
> I tried to do this with
> betwixt. When I do this like in the example on the
> Homepage, betwixt
> converts also the referenzed objects to xml. I only
> want, that betwixt
> converts the primitives types (attributes like
> integer, string.) of the
> current class and not the referenced objects. I
> haven't found a flag to
> configure this yet.
> 
>  
> 
> Any idea?
> 
>  
> 
> Thanks a lot
> 
>  
> 
> Josef Wagner
> 
> 


Ing. Diego H. Mornacco
Epidata Consulting S.R.L. <EPI/>
www.epidataconsulting.com
Cel: 15-5884-0040


"K.I.S.S.: Keep It Simple, S...!"


	


	
		
___________________________________________________________ 
1GB gratis, Antivirus y Antispam 
Correo Yahoo!, el mejor correo web del mundo 
http://correo.yahoo.com.ar 


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