commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ikuki....@nts.ricoh.co.jp
Subject Re: Betwixt - How to control the output in BeanToXml
Date Tue, 21 Sep 2004 13:31:26 GMT

hi, robert
Thanks for you help very much!

But still I can not use it well. I tried a custom ObjectStringConverter and
did not get the output I wished.
My problem is: how to eliminate some object in the output? (Since I do want
to show other null object in the
output XML, I can not use "setWriteEmptyElements" to do that.)
Could you show me some good samples of that?


// ====================================
// Here is the converter I used
// ====================================
public class MyConverter extends ConvertUtilsObjectStringConverter {
      public String objectToString(Object object, Class type, String
flavour, Context context) {
            if ( object == null ) {
                  return "";
            }

            if ( Calendar.class.equals(context.getBean().getClass())
                        ||
GregorianCalendar.class.equals(context.getBean().getClass()) ) {
                  if (Date.class.equals(type)) {

                        DateFormat dateFormat = new
SimpleDateFormat("''yyyy-MM-dd HH:mm:ss.SSS z''");

dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

                        String myTime = dateFormat.format((Date)
((GregorianCalendar) context.getBean()).getTime());
                        return myTime;
                  }
                  return "";
            }

            if ( ZoneInfo.class.equals(context.getBean().getClass()) ) {
                  context.setBean(null);
                  return "";
            }

            return ConvertUtils.convert( object );
      }

      public Object stringToObject(String value, Class type, String
flavour, Context context) {
            ......
      }
}

// ====================================
// Here is the output I got
// ====================================
  <MyBean>
    ......
    ......
    ......
    <myCal>
      <firstDayOfWeek/>
      <gregorianChange>'2004-09-21 13:11:04.234 UTC'</gregorianChange>
      <lenient/>
      <minimalDaysInFirstWeek/>
      <time>'2004-09-21 13:11:04.234 UTC'</time>
      <timeInMillis/>
      <timeZone>
        <DSTSavings/>
        <ID/>
        <displayName/>
        <rawOffset/>
      </timeZone>
    </myCal>
    ......
    ......
    ......
  </MyBean>

// ====================================
// and Here is the output I wished
// ====================================
  <MyBean>
    ......
    ......
    ......
    <myCal>'2004-09-21 13:11:04.234 UTC'</myCal>
    ......
    ......
    ......
  </MyBean>




|---------+-------------------------------------->
|         |           robert burrell donkin      |
|         |           <robertburrelldonkin@blueyo|
|         |           nder.co.uk>                |
|         |                                      |
|         |           2004/09/17 06:46           |
|         |           "Jakarta Commons Users     |
|         |           List" へ返信してください   |
|         |                                      |
|---------+-------------------------------------->
  >------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                      
                                       |
  |       宛先:    "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
                                               |
  |       cc:      (bcc: Ikuki Toh/O/RICOH)                                              
                                       |
  |       件名:    Re: Betwixt - How to control the output in BeanToXml                
                                         |
  >------------------------------------------------------------------------------------------------------------------------------|




(hopefully better late than never)

yes: use a custom object <-> string converter. see
http://jakarta.apache.org/commons/betwixt/guide/binding.html for more
details.

- robert

On 8 Sep 2004, at 04:07, ikuki.toh@nts.ricoh.co.jp wrote:

> hi, I am a beginner of commons.betwixt.
> I just wondering if Betwixt can do this and how : when convert a Bean
> To
> Xml,
> Could betwixt recognize an object in the bean I input, and then change
> the
> output
> of it to another object(exp : Date) in the XML?
>
>
> FOR EXAMPLE :  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> If there is a Calendar in myBean, could Betwixt just write it as a
> Date in
> the output XML?
> // ====================================
> // If the Bean for convert is =>
> // ====================================
> public class MyBean {
>
>     private String id;
>     private String name;
>     private String[] emails;
>     ..........
>     private Calendar myCal;
>
>     ..........
>
> }
>
> // ====================================
> // The output XML I hoped is  =>
> // ====================================
> <?xml version='1.0' encoding='UTF-8'?>
> <mybean>
>   <String>id value</String>
>   <String>name value</String>
>   <String>email value</String>
>     ..........
>   <Date>Date value</Date>
>     ..........
> </mybean>
>
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> appreciate for any re, thanks!
>
> Dong
>
>
>
> ---------------------------------------------------------------------
> 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






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


Mime
View raw message