1

I'm trying to convert a large Map> to some JavaBean. The key of map corresponds to some property of JavaBean, and the value somehow is decoded to property value. So I decided to use some util for that, but don't know what will work. There are some requirements I have to this util (or framework):

  1. all configuration must be in separate files
  2. should be a possibility to map dynamic quantity of keys: there is a map:

    key | value
    quan | n
    key_1| value_1
    key_2| value_2
    ........ | .............
    key_n| value_n

where n - is any number and the JavaBean has a List of some beans. They have a property. value_1, value_2, ... must be mapped in this property, and in the end there must be so much beans in list, as these keys and values in map.

3.. should be a possibility to set up custom decoder for property mapping, because in most cases the value in map is a List with 1 value, so I need to get the first item of list (if it's not empty).

4.. should be a possibility run some script to execute extraordinary mappings, for example: there is a map, that is described in 2d point. and the JavaBean has a property of type HashMap, where value_1 is mapped to Bean1 and some analogous value from input map is mapped to Bean2.

I've tried to use smooks, but when I've started, all these requirements were not clear yet and the smooks was something new, I haven't worked with it until now. So the smooks config doesn't contain the whole business-logic (because of second req.) and looks ugly, I don't like that. I can show the most ugliest fragment for 2d point:

<jb:bean beanId="javaBean" class="com.example.JavaBean" createOnElement="map">
    <jb:wiring property="someBeans" beanIdRef="someBeanItems"/>
</jb:bean>

<jb:bean beanId="someBeanItems" class="java.util.ArrayList" createOnElement="map/entry">
    <jb:wiring beanIdRef="someBeanItem"/>
</jb:bean>

<jb:bean beanId="someBeanItem" class="com.example.someBeanItem" createOnElement="map/entry">
    <condition>map.quan[0]>0</condition>
    <jb:expression property="property1">
        index = map.quan[0]-1;
        value = additionalProperties.property1_List[index];
        map.quan[0] = map.quan[0] - 1;
        return value;
    </jb:expression>
</jb:bean>

Here "property1_List" is builded before executing smooks.

Now I look for something more nice and need your help: maybe you know how to make that better using smooks? Or what another frameworks for mapping can you recommend for my issue?

0 Answers0