Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: JiBX 1.1
-
Fix Version/s: JiBX 1.1.5
-
Component/s: core
-
Labels:None
-
Number of attachments :
Description
I've defined a mapping in my binding like this:
<mapping name="Application" class="Application">
<collection name="MandatoryComponents" create-type="java.util.ArrayList" item-type="ComponentInstance" get-method="getMandatoryComponentInstances" set-method="addMandatoryComponentInstances"/>
</mapping>
I noticed in the bytecode enhanced Application class, the generated unmarshalling method becomes:
public final Application JiBX_application_unmarshal_1_1(UnmarshallingContext arg1)
throws JiBXException
It turns out that the my method getMandatoryComponentInstances(), I am returning an unmodifiable Collection. I do not return null if the collection is empty. When I run my unmarshalling testcase, I will get an UnsupportedOperationException because you cannot add to the collection my method returns.
It seems to me it would be wrong to assume my get-method will return something you can add to. Furthermore, why is the get-method being used for unmarshalling? I already specified a create-type="java.util.ArrayList", so why not just instantiate one of those?
This is by-design, since JiBX explicitly reuses objects when unmarshalling. The get-method attribute documentation should point this out, though, and say that you need to return null if you want a new instance to be created. I'll add this for 1.1.2.