[prev in list] [next in list] [prev in thread] [next in thread]
List: jibx-users
Subject: Re: [jibx-users] Defaull values for attributes.
From: Alexander Pokahr <pokahr () informatik ! uni-hamburg ! de>
Date: 2005-06-23 7:53:53
Message-ID: 42BA6A91.7030103 () informatik ! uni-hamburg ! de
[Download RAW message or body]
Hi Dennis,
thanks for the reply.
I will think about it.
Regards,
Alex
Dennis Sosnoski wrote:
> That's an interesting point - part of the reason for always writing the
> value is to allow object reuse when unmarshalling, but that does create
> the duplication of effort when you want the classes initialized properly
> for direct creation. You're welcome to enter an enhancement request for
> this issue in Jira. Perhaps what's really needed is something like an
> additional choice besides "optional" and "required", along the lines of
> "skip-missing".
>
> - Dennis
>
> Alexander Pokahr wrote:
>
>> Hi again,
>>
>> This works, but is somewhat awkward as i have
>> to duplicate the default value in the binding.xml
>> and in the Java class given that I want to have
>> objects created directly (i.e. "new MyClass()")
>> also initialized with proper default values.
>>
>> But thanks anyway for the quick reply.
>>
>> Kind regards,
>> Alex
>>
>> Dan Cooperstock wrote:
>>
>>> JiBX always sets every field in the class, whether it is optional or
>>> not. You can use the default="value" attribute in JiBX to set defaults.
>>>
>>> -------------------------------------------------------------------
>>> Dan Cooperstock, Senior Software Developer, Quest Software
>>> 260 King St. E., Toronto ON Canada M5A 4L5
>>> dan.cooperstock@quest.com 416-933-5165
>>>
>>> With Quest Software, you can expect more ... more performance, more
>>> productivity, more value from your IT investments.
>>>
>>> Visit www.quest.com to learn how.
>>>
>>>
>>> -----Original Message-----
>>> From: jibx-users-admin@lists.sourceforge.net
>>> [mailto:jibx-users-admin@lists.sourceforge.net] On Behalf Of Alexander
>>> Pokahr
>>> Sent: Wednesday, June 15, 2005 9:52 AM
>>> To: jibx-users@lists.sourceforge.net
>>> Subject: [jibx-users] Defaull values for attributes.
>>>
>>> Hi all,
>>>
>>> I have an XML schema which contains default values for some attributes,
>>> so that these can be omitted in XML files.
>>>
>>> I thought, a good way to map this to Java would be to have fields which
>>> are initialized to this default value.
>>>
>>> Unfortunately, JiBX overwrites these fields in any case (even when the
>>> attribute is omitted in the XML file).
>>>
>>> I attached a small test case that I did to verify this behaviour.
>>>
>>> When I run the test it prints:
>>> "Test value is: null"
>>>
>>> I would rather expect:
>>> "Test value is: default value"
>>>
>>> Is this a bug in JiBX, or is there a reason, why the initial field value
>>> gets overwritten?
>>>
>>> Thanks,
>>> Alex
>>>
>>>
>>> -- test_binding.xml:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <binding>
>>>
>>> <mapping class="Test" name="test">
>>> <value name="value" field="value" usage="optional"
>>> style="attribute"/>
>>> </mapping>
>>>
>>> </binding>
>>>
>>>
>>> -- test.xml:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <test/>
>>>
>>>
>>> -- Test.java:
>>>
>>> import java.io.FileInputStream;
>>>
>>> import org.jibx.runtime.BindingDirectory;
>>> import org.jibx.runtime.IBindingFactory; import
>>> org.jibx.runtime.IUnmarshallingContext;
>>>
>>> public class Test
>>> {
>>> private String value = "default value";
>>>
>>> public static void main(String[] args)
>>> {
>>> try
>>> {
>>> // Read an object from xml
>>> IBindingFactory bfa =
>>> BindingDirectory.getFactory(Test.class);
>>> IUnmarshallingContext uc =
>>> bfa.createUnmarshallingContext();
>>> Test t = (Test)uc.unmarshalDocument(new
>>> FileInputStream("test.xml"), null);
>>> System.out.println("Test value is: "+t.value);
>>> }
>>> catch(Exception e)
>>> {
>>> e.printStackTrace();
>>> }
>>> }
>>> }
>>>
>>>
>>>
>>> -------------------------------------------------------
>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
>>> from IBM. Find simple to follow Roadmaps, straightforward articles,
>>> informative Webcasts and more! Get everything you need to get up to
>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
>>> _______________________________________________
>>> jibx-users mailing list
>>> jibx-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jibx-users
>>>
>>>
>>>
>>> -------------------------------------------------------
>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
>>> from IBM. Find simple to follow Roadmaps, straightforward articles,
>>> informative Webcasts and more! Get everything you need to get up to
>>> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&opĚk
>>> _______________________________________________
>>> jibx-users mailing list
>>> jibx-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jibx-users
>>
>>
>>
>>
>> -------------------------------------------------------
>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
>> from IBM. Find simple to follow Roadmaps, straightforward articles,
>> informative Webcasts and more! Get everything you need to get up to
>> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&opĚk
>> _______________________________________________
>> jibx-users mailing list
>> jibx-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jibx-users
>>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&opĚk
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&opĚk
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic