commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ray <ray_off...@yahoo.co.uk>
Subject Re: [Commons Digester] Newbie (ish) help with odd structure
Date Sat, 14 May 2005 12:31:07 GMT
Thanks Simon; that's exactly what I'm looking for. .. :-)

One question though; does this also for marshalling the object back into 
XML, or do I need to provide a separate converter that takes a 
DataString and return a String?

Or does it just use a toString call on the object?

Thanks again.


Simon Kitching wrote:

>Hi Ray,
>
>On Sat, 2005-05-14 at 10:14 +0100, Ray wrote:
>  
>
>>public class DataItem {
>>
>>    private DataString name = new DataString();
>>    private DataString postcode = new DataString();
>>
>>    public DataString getName();
>>    public void setName(DataString name);
>>    public DataString getPostcode();
>>    public void setPostcode(DataString postcode);
>>
>>}
>>
>>
>>public class DataString {
>>
>>    private String value;
>>
>>    public String getValue();
>>    public void setValue(String name);
>>
>>  
>>}
>>
>>
>>Okay, I have the following XML data
>>
>><Request>
>>    <DataItem>
>>        <Name>Frederick</Name>
>>        <Postcode>xxx112223</Postcode>
>>    </DataItem>
>></Request>
>>
>>    
>>
>
>I think you could solve this by registering a custom converter that can
>convert String objects into DataString objects. 
>
>When Digester needs to call a method that takes a non-string parameter,
>but it has just the string data extracted from the XML it uses the
>beanutils ConvertUtils library to do the appropriate conversion. It
>looks to me like you just need to tell ConvertUtils how to create a
>DataString out of a String..
>
>ConvertUtils.register(DataString.class, new Converter()) {
>  public Object convert(Class Type, Object value) {
>    if (value == null)
>	return null;
>    else
>        return new DataString(value.toString());
>  }
>}
>
>I presume a DataString has a constructor that takes a String. If not,
>obviously creating an empty one and setting the value is also possible.
>
>See here for details on beanutils:
>  http://jakarta.apache.org/commons/beanutils
>
>Regards,
>
>Simon
>
>
>---------------------------------------------------------------------
>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