castor

unmarshalling fails for constructor with arguments

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1
  • Fix Version/s: 1.1.1
  • Component/s: XML
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    6

Description

I tried to unmarshall XML data for a class SimpleMessage that has a constructor with two parameters. The type of the second parameter is an enum-like class Severity (without a valueOf() method). Now, there seems to be a problem, when unmarshalling data.

sample data:

<SimpleMessage severity="Warning" text="marked object as obsolete"/>

<SimpleMessage severity="Error" text="must shut down system">

The following mapping was used:

<mapping>
<class name="sample.SimpleMessage" verify-constructable="false">
<map-to xml="SimpleMessage" />
<field name="severity" type="sample.Severity" get-method="severity" set-method="%2" handler="sample.SeverityHandler">
<bind-xml name="severity" node="attribute"/>
</field>
<field name="formattedText" type="java.lang.String" get-method="formattedText" set-method="%1" >
<bind-xml name="text" node="attribute"/>
</field>
</class>

</mapping>

The code for the domain classes, the handler, the mapping and a test case is attached.
Maybe I'm just missing something?

Activity

Hide
Werner Guttmann added a comment -

How about attaching the Severity class as well, as it's being referenced ?

Show
Werner Guttmann added a comment - How about attaching the Severity class as well, as it's being referenced ?
Hide
Uwe Langbecker added a comment -

Missing source code attached.

Show
Uwe Langbecker added a comment - Missing source code attached.
Hide
Werner Guttmann added a comment -

It looks like in UnmarshallHandler.processConstructorArgs(), there's code missing that deals with enum-style argument types.

Show
Werner Guttmann added a comment - It looks like in UnmarshallHandler.processConstructorArgs(), there's code missing that deals with enum-style argument types.
Hide
Werner Guttmann added a comment -

JUnit test case relative to src/bugs.

Show
Werner Guttmann added a comment - JUnit test case relative to src/bugs.
Hide
Werner Guttmann added a comment -

Initial patch for review. XML CTF still runs fine .. .

Show
Werner Guttmann added a comment - Initial patch for review. XML CTF still runs fine .. .
Hide
Werner Guttmann added a comment -

Improved patch.

Show
Werner Guttmann added a comment - Improved patch.
Hide
Werner Guttmann added a comment -

By the way, the solution implemented will remove the requirement to provide a special field handler.

Show
Werner Guttmann added a comment - By the way, the solution implemented will remove the requirement to provide a special field handler.
Hide
Werner Guttmann added a comment -

Final patch for review, incl. new CTF test case.

Show
Werner Guttmann added a comment - Final patch for review, incl. new CTF test case.
Hide
Uwe Langbecker added a comment -

Hello Werner,

can you please suggest how to update the sample mapping - possibly without custom handler? I have difficulties with the 2-argument constructor of SimpleMessage, where the second argument is an enumeration instance and hence cannot be created directly.

Thanks,
Uwe

Show
Uwe Langbecker added a comment - Hello Werner, can you please suggest how to update the sample mapping - possibly without custom handler? I have difficulties with the 2-argument constructor of SimpleMessage, where the second argument is an enumeration instance and hence cannot be created directly. Thanks, Uwe
Hide
Werner Guttmann added a comment -

Uwe, I'd rather actually get functionality added to Castor so that this is possible with out having to write any FieldHandlers or whatsoever ... most of the functionality is there already, it's just a matter of re-wiring thigs.

Show
Werner Guttmann added a comment - Uwe, I'd rather actually get functionality added to Castor so that this is possible with out having to write any FieldHandlers or whatsoever ... most of the functionality is there already, it's just a matter of re-wiring thigs.
Hide
Uwe Langbecker added a comment -

That sounds like a good approach. Since I could not find the testcase in the trunk, after setting it up anew, I couldn't get it running with or without field handler.

Show
Uwe Langbecker added a comment - That sounds like a good approach. Since I could not find the testcase in the trunk, after setting it up anew, I couldn't get it running with or without field handler.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: