As it says in the tutorial:

"Hashmap handling makes an especially good example of the situations that require custom marshaller/unmarshallers. This particular implementation handles one particular form of hashmaps, with string keys and values of an object type with a *mapping* definition within the JiBX binding file. Other forms of hashmaps could be handled by modifying the basic marshaller/unmarshaller code, but it's very difficult to handle all possible types of hashmaps with a single implementation. Consider how the XML structure would need to be different if the key values in the hashmap were other mapped objects rather than simple string values, for instance (they couldn't be expressed in XML as attribute values, for starters)."

The supplied org.jibx.extras.HashMapperStringToComplex is an example of how to handle the most common situation. You need to modify it to work with other situations. And please don't come back with a "how do I modify it" question - go through the code and learn how it works, then try modifying it to see the results.

 - Dennis

babloosony wrote:

Hi,

I have below java class :

public class Forecast
{
        ...
        private HashMap hashMap;
        ...
        // usual getter and setter methods for hashMap
        ...
}


Now I am having below binding definition : <binding> <mapping class="Forecast" name="forecast"> <value name="state" field="state" usage="optional"/> <value name="zip" field="zip" usage="optional"/> <value name="precip" field="precip" usage="optional"/> <value name="date" field="date" usage="optional"/> <value name="hi" field="hi" usage="optional"/> <value name="city" field="city" usage="optional"/> <value name="forecast" field="forecast" usage="optional"/> <value name="low" field="low" usage="optional"/> <structure field="temp" name="temperature" > <value name="temp" field="temp" /> </structure> <structure field="hashMap" /> <collection field="dummyVector" usage="optional"> <value style="element" name="vectorElement" /> </collection> </mapping>

        <mapping name="customer" class="Customer" >
               <value name="street" field="street" />
               <value name="city" field="city" />
               <value name="state" field="state"/>
               <value name="zip" field="zip"/>
        </mapping>
        
        <mapping class="java.util.HashMap" name="map"
marshaller="org.jibx.extras.HashMapperStringToComplex"
unmarshaller="org.jibx.extras.HashMapperStringToComplex"/>
</binding>


I can un(marshal) HashMap's that can contain key as java.lang.String and value as Customer object but my doubts are below:

1. how to handle HashMap's containing java.lang.String as value ? Do
we need to define a binding for java.lang.String ?
2. how to handle HashMap's contain Customer object as key or say
java.lang.Integer as key ?


I dont find answers in JiBX tutorials relate to my above questions. Please suggest ...



Thanks & Regards,
Kumar.


------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users





-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to