JiBX
  1. JiBX
  2. JIBX-77

Collection type attribute should be used only for unmarshalling and not for marshalling

    Details

    • Type: Wish Wish
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-RC0
    • Fix Version/s: JiBX 1.1 beta4
    • Component/s: core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Hi,
      I am using Jibx with Hibernate.
      Now i have a Model which has a property of type java.util.Set. Now there are two scenario's in which this set would be initalised. one where Hibernate loads it in which case the instance would be org.hibernate.PersistentSet and in another case i would load the set in which case the instance would be java.util.HashSet.

      Now the problem is when i define the Mapping i give the
      <structure name="su">
      <collection field="csu" type="java.util.HashSet"/>
      </structure>

      Now when i marshall the data from hibernate i get a classcastexception.

      I expect this Hashset to be used only in the case of unmarshalling where a new instance for that property has to be created.
      Since other wise all marshalling operation can happen against the Interface itself.

      But it is not happening so. The type is being used for both unmarshalling/marshalling . what i would prefer is a scenario where the declared type of the property is used for marshalling and the type specified for the collection tag used for creating the new instance's only.

        Activity

        Hide
        Dennis Sosnoski added a comment -

        Probably the best way of handling this is by adding a new attribute with a name like "create-type" which is used only for determining the type of object to create when unmarshalling. The current "type" attribute has this effect, but it also effects everything else (including method lookup).

        As a workaround for your problem, just define a static factory method to create instances of HashSet and use the "factory" attribute on the collection. This will take care of your issue without effecting the marshalling behavior.

        Show
        Dennis Sosnoski added a comment - Probably the best way of handling this is by adding a new attribute with a name like "create-type" which is used only for determining the type of object to create when unmarshalling. The current "type" attribute has this effect, but it also effects everything else (including method lookup). As a workaround for your problem, just define a static factory method to create instances of HashSet and use the "factory" attribute on the collection. This will take care of your issue without effecting the marshalling behavior.
        Hide
        Dennis Sosnoski added a comment -

        Implemented create-type attribute to handle this situation.

        Show
        Dennis Sosnoski added a comment - Implemented create-type attribute to handle this situation.

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Jagannathan
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: