castor

Random Order of Elements While Marshalling (Using Mapping xml)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.1.2.1
  • Fix Version/s: 1.3 rc1
  • Component/s: XML
  • Labels:
    None
  • Environment:
    JDK 1.4.12, OS: Windows XP, IDE: Eclipse
  • Testcase included:
    yes
  • Number of attachments :
    9

Description

I am using a Castor mapping file to marshal java objects to XML. I have read in forums that using a mapping file ensures that elements in the resulting xml will be exactly in the same order as they have been defined in the mapping file. But I see different ordering in different cases. Additionally, I sometimes see that attributes disappear from the resulting xml.

This is my mapping file:
-----------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<cst:mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cst="http://castor.exolab.org/"
xmlns="http://ACORD.org/Standards/Life/2"
xsi:schemaLocation="http://castor.exolab.org/ mapping.xsd">

<cst:class name="com.test.model.Person">
<cst:field name="firstName" type="java.lang.String">
<cst:bind-xml name="FirstName" node="element"/>
</cst:field>
<cst:field name="middleName" type="java.lang.String">
<cst:bind-xml name="MiddleName" node="element"/>
</cst:field>
<cst:field name="lastName" type="java.lang.String">
<cst:bind-xml name="LastName" node="element"/>
</cst:field>
<cst:field name="prefix" type="java.lang.String">
<cst:bind-xml name="Prefix" node="element"/>
</cst:field>
<cst:field name="suffix" type="java.lang.String">
<cst:bind-xml name="Suffix" node="element"/>
</cst:field>
<cst:field name="birthDate" type="java.lang.String" handler="com.test.fieldhandler.DateHandler">
<cst:bind-xml name="BirthDate" node="element"/>
</cst:field>
</cst:class>

<cst:class name="com.test.model.Party">
<cst:field name="id" type="java.lang.String">
<cst:bind-xml name="id" node="attribute"/>
</cst:field>
<cst:field name="partyTypeCode" type="java.lang.String">
<cst:bind-xml name="PartyTypeCode" node="element"/>
</cst:field>
<cst:field name="partyTypeCodeCode" type="java.lang.String">
<cst:bind-xml name="tc" node="attribute" location="PartyTypeCode"/>
</cst:field>
<cst:field name="fullName" type="java.lang.String">
<cst:bind-xml name="FullName" node="element"/>
</cst:field>
<cst:field name="govtID" type="java.lang.String">
<cst:bind-xml name="GovtID" node="element"/>
</cst:field>
<cst:field name="govtIDTC" type="java.lang.String">
<cst:bind-xml name="GovtIDTC" node="element"/>
</cst:field>
<cst:field name="govtIDTCCode" type="java.lang.String">
<cst:bind-xml name="tc" node="attribute" location="GovtIDTC"/>
</cst:field>
<cst:field name="residenceState" type="java.lang.String">
<cst:bind-xml name="ResidenceState" node="element"/>
</cst:field>
<cst:field name="person" type="com.test.model.Person">
<cst:bind-xml name="Person" node="element"/>
</cst:field>
</cst:class>

</cst:mapping>

This is the java class that I use for testing:
----------------------------------------------------------

public class MarshallerTest {
public static void main (String[] args) {
Party party = getParty();

try { Mapping map = new Mapping(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL mappingFileURL = classLoader.getResource("Mapping.xml"); map.loadMapping(mappingFileURL); Marshaller marshaller = new Marshaller(); marshaller.setMapping(map); marshaller.setNamespaceMapping("", "http://ACORD.org/Standards/Life/2"); marshaller.setSuppressNamespaces(true); StringWriter writer = new StringWriter(); marshaller.setWriter(writer); marshaller.marshal(party); System.out.println(writer.toString()); } catch (Exception e) { e.printStackTrace(); }
}

private static Party getParty() { Party party = new Party(); party.setId("PaidProducerGUID1"); party.setPartyTypeCode("Person"); party.setPartyTypeCodeCode("1"); party.setGovtID("000000000"); party.setGovtIDTC("SSN"); party.setGovtIDTCCode("11"); Person person = new Person(); person.setFirstName("Andy"); person.setMiddleName("S"); person.setLastName("Roddick"); person.setPrefix("Mr."); party.setPerson(person); return party; }
}

This is the result I expect:
--------------------------------------

<party xmlns="http://ACORD.org/Standards/Life/2" id="PaidProducerGUID1">
<PartyTypeCode tc="1"/>
<GovtID>000000000</GovtID>
<GovtIDTC tc="11"/>
<Person>
<FirstName>Andy</FirstName>
<MiddleName>S</MiddleName>
<LastName>Roddick</LastName>
<Prefix>Mr.</Prefix>
</Person>
</party>

But, this is the result I get (elements PartyTypeCode and GovtIDTC are not in their correct position):
---------------------------------------------------------------------------------------------------------------------------------------

<party xmlns="http://ACORD.org/Standards/Life/2" id="PaidProducerGUID1">
<GovtID>000000000</GovtID>
<Person>
<FirstName>Andy</FirstName>
<MiddleName>S</MiddleName>
<LastName>Roddick</LastName>
<Prefix>Mr.</Prefix>
</Person>
<PartyTypeCode tc="1"/>
<GovtIDTC tc="11"/>
</party>

Can you please see what is causing the incorrect element ordering? The xml has a strict ordering as it has to be validated against a schema and validation fails if the order is incorrect.

Many thanks,

Tausif

Activity

Hide
Tausif Farooqi added a comment -

I'm sorry... this is the test class:

import java.io.StringWriter;
import java.net.URL;

import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.xml.Marshaller;

import com.objectedge.acord.model.Party;
import com.objectedge.acord.model.Person;

public class MarshallerTest {
public static void main (String[] args) {
Party party = getParty();

try { Mapping map = new Mapping(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL mappingFileURL = classLoader.getResource("Mapping.xml"); map.loadMapping(mappingFileURL); Marshaller marshaller = new Marshaller(); marshaller.setMapping(map); marshaller.setNamespaceMapping("", "http://ACORD.org/Standards/Life/2"); marshaller.setSuppressNamespaces(true); StringWriter writer = new StringWriter(); marshaller.setWriter(writer); marshaller.marshal(party); System.out.println(writer.toString()); } catch (Exception e) { e.printStackTrace(); }
}

private static Party getParty() { Party party = new Party(); party.setId("PaidProducerGUID1"); party.setPartyTypeCode(null); // DELIBERATELY SETTING NULL HERE party.setPartyTypeCodeCode("1"); party.setGovtID("000000000"); party.setGovtIDTC(null); // DELIBERATELY SETTING NULL HERE party.setGovtIDTCCode("11"); Person person = new Person(); person.setFirstName("Andy"); person.setMiddleName("S"); person.setLastName("Roddick"); person.setPrefix("Mr."); party.setPerson(person); return party; }
}

Show
Tausif Farooqi added a comment - I'm sorry... this is the test class: import java.io.StringWriter; import java.net.URL; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.xml.Marshaller; import com.objectedge.acord.model.Party; import com.objectedge.acord.model.Person; public class MarshallerTest { public static void main (String[] args) { Party party = getParty(); try { Mapping map = new Mapping(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL mappingFileURL = classLoader.getResource("Mapping.xml"); map.loadMapping(mappingFileURL); Marshaller marshaller = new Marshaller(); marshaller.setMapping(map); marshaller.setNamespaceMapping("", "http://ACORD.org/Standards/Life/2"); marshaller.setSuppressNamespaces(true); StringWriter writer = new StringWriter(); marshaller.setWriter(writer); marshaller.marshal(party); System.out.println(writer.toString()); } catch (Exception e) { e.printStackTrace(); } } private static Party getParty() { Party party = new Party(); party.setId("PaidProducerGUID1"); party.setPartyTypeCode(null); // DELIBERATELY SETTING NULL HERE party.setPartyTypeCodeCode("1"); party.setGovtID("000000000"); party.setGovtIDTC(null); // DELIBERATELY SETTING NULL HERE party.setGovtIDTCCode("11"); Person person = new Person(); person.setFirstName("Andy"); person.setMiddleName("S"); person.setLastName("Roddick"); person.setPrefix("Mr."); party.setPerson(person); return party; } }
Hide
Werner Guttmann added a comment -

Hi, can you please attach all relevant files rather than inlining them, and also attach your domain classes, as otherwise I won't be able to run your test. Thanks in advance

Show
Werner Guttmann added a comment - Hi, can you please attach all relevant files rather than inlining them, and also attach your domain classes, as otherwise I won't be able to run your test. Thanks in advance
Hide
Tausif Farooqi added a comment -

Hi Werner, thank you very much for responding so quickly. You are right, I should have attached the code rather than pasting it inline. Sorry about that. I've attached the zip file with relevant code and libraries. The zip contains

  • 2 model classes
  • 1 tester class (MarshallerTester.java)
  • Castor mapping file
  • libraries

After I logged this issue I did a little debugging my self and I think the issue is that non-null attributes that belong elements containing null text are processed in the end and hence are written in the wrong order. For example, the test that I have attached the <Party> element contains two elements <PartyTypeCode> (element #1) and <GovtIDTC> (element #4). Both of these elements have an attribute called "tc". When Castor Marshals these elements and finds that the text value is null it does not process their attributes right away but stores them for processing later. Once the Marhsaller has processed every element it checks if there are any remaining attributes left to be processed (line 1907 in Marshaller.java). Hence these 2 elements that were supposed to be at position #1 and position #4 under <Party> are now placed at the end.

Another non-related "problem" that I found was at line 1358 of Marshaller.java. After a matching attribute is found the class does "mstate.nestedAttCount = 0;", should this not be "--mstate.nestedAttCount;"? Please correct me if I am wrong.

Best regards,

Tausif

Show
Tausif Farooqi added a comment - Hi Werner, thank you very much for responding so quickly. You are right, I should have attached the code rather than pasting it inline. Sorry about that. I've attached the zip file with relevant code and libraries. The zip contains
  • 2 model classes
  • 1 tester class (MarshallerTester.java)
  • Castor mapping file
  • libraries
After I logged this issue I did a little debugging my self and I think the issue is that non-null attributes that belong elements containing null text are processed in the end and hence are written in the wrong order. For example, the test that I have attached the <Party> element contains two elements <PartyTypeCode> (element #1) and <GovtIDTC> (element #4). Both of these elements have an attribute called "tc". When Castor Marshals these elements and finds that the text value is null it does not process their attributes right away but stores them for processing later. Once the Marhsaller has processed every element it checks if there are any remaining attributes left to be processed (line 1907 in Marshaller.java). Hence these 2 elements that were supposed to be at position #1 and position #4 under <Party> are now placed at the end. Another non-related "problem" that I found was at line 1358 of Marshaller.java. After a matching attribute is found the class does "mstate.nestedAttCount = 0;", should this not be "--mstate.nestedAttCount;"? Please correct me if I am wrong. Best regards, Tausif
Hide
Tausif Farooqi added a comment -

Code attached...

Show
Tausif Farooqi added a comment - Code attached...
Hide
Werner Guttmann added a comment -

Can you attach a patch relative to SVN trunk that identifies the code areas in question with e,g, // TODO and/ or comments ? I am just looking at the test case you have provided, and anything that makes my life easier would be appreciated.

Show
Werner Guttmann added a comment - Can you attach a patch relative to SVN trunk that identifies the code areas in question with e,g, // TODO and/ or comments ? I am just looking at the test case you have provided, and anything that makes my life easier would be appreciated.
Hide
Werner Guttmann added a comment -

Just noticed that you are extensively using the location attribute to structure your XML output. Given the high number of comments in e.g. MarshallerFramwork.java, personally I'd consider this area to be ... well, quite buggy (at least).

Having said that, let's have a look at this in detail. I know from some earlier 'peeks' at this code area that this 'processing later' is done on purpose. Don't ask me why, as I cannot remember right now. Just thinking aloud ....

Show
Werner Guttmann added a comment - Just noticed that you are extensively using the location attribute to structure your XML output. Given the high number of comments in e.g. MarshallerFramwork.java, personally I'd consider this area to be ... well, quite buggy (at least). Having said that, let's have a look at this in detail. I know from some earlier 'peeks' at this code area that this 'processing later' is done on purpose. Don't ask me why, as I cannot remember right now. Just thinking aloud ....
Hide
Tausif Farooqi added a comment -

This may sound stupid, but I couldn't figure out how to get a username/password for commiting changes into the code repository. I checked out the latest code from https://svn.codehaus.org/castor/castor/trunk/src/main/java/ (HEAD) and added TODOs which point the possible problem areas. There is just one java file org.exolab.castor.xml.Marshaller.java which I have added comments to. Since I could not check in the file I'm attaching it here along with the 'diff' file. I hope this is okay.

Thanks,

Tausif

Show
Tausif Farooqi added a comment - This may sound stupid, but I couldn't figure out how to get a username/password for commiting changes into the code repository. I checked out the latest code from https://svn.codehaus.org/castor/castor/trunk/src/main/java/ (HEAD) and added TODOs which point the possible problem areas. There is just one java file org.exolab.castor.xml.Marshaller.java which I have added comments to. Since I could not check in the file I'm attaching it here along with the 'diff' file. I hope this is okay. Thanks, Tausif
Hide
Tausif Farooqi added a comment -

Attached java file

Show
Tausif Farooqi added a comment - Attached java file
Hide
Tausif Farooqi added a comment -

Attached the diff file...

Show
Tausif Farooqi added a comment - Attached the diff file...
Hide
Werner Guttmann added a comment -

> This may sound stupid, but I couldn't figure out how to get a username/password for
> commiting changes into the code repository.
Well, you shouldn't, as you are not a committer. Only committers get a username/password combo for write access to the SVN repository. That's why I asked you to attach a patch (aka a unified diff) for the classes you want to see changed/looked at. As simple as that.

In other words, checking out from https://svn.codehaus.org/castor/castor/trunk/ is the correct thing to do. And all I need is a unified diff ... to make me (us) happy.

Show
Werner Guttmann added a comment - > This may sound stupid, but I couldn't figure out how to get a username/password for > commiting changes into the code repository. Well, you shouldn't, as you are not a committer. Only committers get a username/password combo for write access to the SVN repository. That's why I asked you to attach a patch (aka a unified diff) for the classes you want to see changed/looked at. As simple as that. In other words, checking out from https://svn.codehaus.org/castor/castor/trunk/ is the correct thing to do. And all I need is a unified diff ... to make me (us) happy.
Hide
Werner Guttmann added a comment -

Updated patch without the whitespace changes, relative to src/main/java.

Show
Werner Guttmann added a comment - Updated patch without the whitespace changes, relative to src/main/java.
Hide
Werner Guttmann added a comment -

I just had a look at the diff, and I really appreciate your help. Makes it much easier for me to pin-point any areas where we might have to change code. With regards to the issue at line 1358ff, can you think about a test case that demonstrates that this bug makes things fail ?

Show
Werner Guttmann added a comment - I just had a look at the diff, and I really appreciate your help. Makes it much easier for me to pin-point any areas where we might have to change code. With regards to the issue at line 1358ff, can you think about a test case that demonstrates that this bug makes things fail ?
Hide
Werner Guttmann added a comment -

Just looking at lines 1773ff (where you inserted one of your TODOs), I think that this issue is occuring because you have not modelled a fully-fledged Java object for the <partyTypeCode> element, with its own members for e.g. the attributes. In this case I am 100% sure that Castor would be capable of marshalling things fine.

Well, back to your problem, the use of the location attribute in this case. I wonder how such a check might actually look like. Normally I'd want to consult with the descriptor class for the <partyTypeCode> element whether there's any attributes defined on this class, which I would have to include in a check. But in your case, there is not such information available.

I guess I will have to debug a little bit more ....

Show
Werner Guttmann added a comment - Just looking at lines 1773ff (where you inserted one of your TODOs), I think that this issue is occuring because you have not modelled a fully-fledged Java object for the <partyTypeCode> element, with its own members for e.g. the attributes. In this case I am 100% sure that Castor would be capable of marshalling things fine. Well, back to your problem, the use of the location attribute in this case. I wonder how such a check might actually look like. Normally I'd want to consult with the descriptor class for the <partyTypeCode> element whether there's any attributes defined on this class, which I would have to include in a check. But in your case, there is not such information available. I guess I will have to debug a little bit more ....
Hide
Tausif Farooqi added a comment -

> With regards to the issue at line 1358ff, can you think about a test case that demonstrates that this bug makes things fail ?

I don't think the problem lies on this line as the code is simply not processing the attributes that do not belong to that current element. In my opinion the problem is on 1773 (for which the original test case MarshallerTest.java was provided). We get the 'text' value of the element on line 1760:

obj = elemDescriptor.getHandler().getValue(object);

And then we perform the following checks on lines 1773 and 1774

if (obj == null || (obj instanceof Enumeration && !((Enumeration)obj).hasMoreElements())) {
                if (elemDescriptor.isNillable() && (elemDescriptor.isRequired())) {
                    nil = true;
                }
                else continue;
            }

This means that if the element value is null and the element is not defined as 'required' then we skip further processing (the continue statement), such as processing attributes, and move on to the next iteration. This in turn means that these attributes will be processed at the end and will result in incorrect ordering of their respective elements. Does that make sense? Or have I got it completely wrong?

> Just looking at lines 1773ff (where you inserted one of your TODOs), I think that this issue is occuring because you have not modelled a
> fully-fledged Java object for the <partyTypeCode> element, with its own members for e.g. the attributes

All elements and attributes are mapped to the Java object. Eg, If you see the test class MarshallerTest.java:

line 37 sets PartyTypeCode – mapped to – The element PartyTypeCode
line 38 sets PartyTypeCodeCode – mapped to – The attribute PartyTypecode/@tc

Similarly,

line 40 sets GovtIDTC – mapped to – The element GovtIDTC
line 41 sets GovtIDTCCode – mapped to – The attribute GovtIDTC/@tc

These are the elements/attributes I was having a problem with when element value was set to null (MarshallerTest.java, lines 37 and 40) but its attribute was not null (MarshallerTest.java, lines 38 and 41).

Also, if you look at the comment on line 1376 in class Marshaller.java, the statement that follows (should I raise this as a separate bug?):

mstate.nestedAttCount = 0;

This sometimes causes attributes to not be processed. I've attached a second test class (works with the same mapping file and model classes) which replicates this problem. If you run this class you will see that the resulting xml does not contain the attribute for element <GovtIDTC>. This should have had an attribute "tc" with value "11".

Show
Tausif Farooqi added a comment - > With regards to the issue at line 1358ff, can you think about a test case that demonstrates that this bug makes things fail ? I don't think the problem lies on this line as the code is simply not processing the attributes that do not belong to that current element. In my opinion the problem is on 1773 (for which the original test case MarshallerTest.java was provided). We get the 'text' value of the element on line 1760:
obj = elemDescriptor.getHandler().getValue(object);
And then we perform the following checks on lines 1773 and 1774
if (obj == null || (obj instanceof Enumeration && !((Enumeration)obj).hasMoreElements())) {
                if (elemDescriptor.isNillable() && (elemDescriptor.isRequired())) {
                    nil = true;
                }
                else continue;
            }
This means that if the element value is null and the element is not defined as 'required' then we skip further processing (the continue statement), such as processing attributes, and move on to the next iteration. This in turn means that these attributes will be processed at the end and will result in incorrect ordering of their respective elements. Does that make sense? Or have I got it completely wrong? > Just looking at lines 1773ff (where you inserted one of your TODOs), I think that this issue is occuring because you have not modelled a > fully-fledged Java object for the <partyTypeCode> element, with its own members for e.g. the attributes All elements and attributes are mapped to the Java object. Eg, If you see the test class MarshallerTest.java: line 37 sets PartyTypeCode – mapped to – The element PartyTypeCode line 38 sets PartyTypeCodeCode – mapped to – The attribute PartyTypecode/@tc Similarly, line 40 sets GovtIDTC – mapped to – The element GovtIDTC line 41 sets GovtIDTCCode – mapped to – The attribute GovtIDTC/@tc These are the elements/attributes I was having a problem with when element value was set to null (MarshallerTest.java, lines 37 and 40) but its attribute was not null (MarshallerTest.java, lines 38 and 41). Also, if you look at the comment on line 1376 in class Marshaller.java, the statement that follows (should I raise this as a separate bug?):
mstate.nestedAttCount = 0;
This sometimes causes attributes to not be processed. I've attached a second test class (works with the same mapping file and model classes) which replicates this problem. If you run this class you will see that the resulting xml does not contain the attribute for element <GovtIDTC>. This should have had an attribute "tc" with value "11".
Hide
Tausif Farooqi added a comment -

Attached MarshallerTest2.java

Show
Tausif Farooqi added a comment - Attached MarshallerTest2.java
Hide
Werner Guttmann added a comment -

Sorry for the confusion, but let's try it again. I'd like to keep the two issues completely apart, as they are somehow not related. When I asked you about lines 1358ff, I was referring to the 'might miss attributes completely' only. I will have a look at your second test case as well, but first focus on the main problem of yours - as described above.

Show
Werner Guttmann added a comment - Sorry for the confusion, but let's try it again. I'd like to keep the two issues completely apart, as they are somehow not related. When I asked you about lines 1358ff, I was referring to the 'might miss attributes completely' only. I will have a look at your second test case as well, but first focus on the main problem of yours - as described above.
Hide
Werner Guttmann added a comment -

Looking at the (right now incorrect) check for null at lines 1773, I think that we need to start considering the nestedAtts variable for additional checks. I will think about a few things over the weekend, and hopefully be able to attach a preliminary patch somewhen early next week. As far as I can tell, a few methods that check the field descriptors stored within 'nestedAtts' for partial name 'equality' should do the trick, and allow us to refine the check at line 1773.

Show
Werner Guttmann added a comment - Looking at the (right now incorrect) check for null at lines 1773, I think that we need to start considering the nestedAtts variable for additional checks. I will think about a few things over the weekend, and hopefully be able to attach a preliminary patch somewhen early next week. As far as I can tell, a few methods that check the field descriptors stored within 'nestedAtts' for partial name 'equality' should do the trick, and allow us to refine the check at line 1773.
Hide
Werner Guttmann added a comment -

First idea of a patch, adding an additional check to cater for nested attributes when the element content is 'null'. Problem is that this doesn't take us anywhere as there's apparently a few more things that need to be changed.

Show
Werner Guttmann added a comment - First idea of a patch, adding an additional check to cater for nested attributes when the element content is 'null'. Problem is that this doesn't take us anywhere as there's apparently a few more things that need to be changed.
Hide
Oliver Nautsch added a comment -

I have the same problem after upgrading castor from version 0.9.5.4 to 1.1.2.1. How is the status of this bug?

Show
Oliver Nautsch added a comment - I have the same problem after upgrading castor from version 0.9.5.4 to 1.1.2.1. How is the status of this bug?
Hide
Werner Guttmann added a comment -

Work in progress ....

Show
Werner Guttmann added a comment - Work in progress ....
Hide
Rainer Mueller added a comment -

Any news on this issue?

Show
Rainer Mueller added a comment - Any news on this issue?
Hide
Werner Guttmann added a comment -

Work in progress ... as much as quite some other bugs.

Show
Werner Guttmann added a comment - Work in progress ... as much as quite some other bugs.
Hide
Mastermnd added a comment -

I am using Castor 1.2 and have hit this bug. I think the perfect explanation is:

[quote]
This means that if the element value is null and the element is not defined as 'required' then we skip further processing (the continue statement), such as processing attributes, and move on to the next iteration. This in turn means that these attributes will be processed at the end and will result in incorrect ordering of their respective elements. Does that make sense? Or have I got it completely wrong?
[/quote]

My optional elements with a location attribute are being generated in a different order. Unfortunatelly, this means that I cannot use Castor in my project, because I cannot change the XSD of my resulting marshalled object

Anyway, thank you for your hard work.

Show
Mastermnd added a comment - I am using Castor 1.2 and have hit this bug. I think the perfect explanation is: [quote] This means that if the element value is null and the element is not defined as 'required' then we skip further processing (the continue statement), such as processing attributes, and move on to the next iteration. This in turn means that these attributes will be processed at the end and will result in incorrect ordering of their respective elements. Does that make sense? Or have I got it completely wrong? [/quote] My optional elements with a location attribute are being generated in a different order. Unfortunatelly, this means that I cannot use Castor in my project, because I cannot change the XSD of my resulting marshalled object Anyway, thank you for your hard work.
Hide
Werner Guttmann added a comment -

I am already having a look at this problem (again). Any contributions from your side would be welcome ...

Show
Werner Guttmann added a comment - I am already having a look at this problem (again). Any contributions from your side would be welcome ...
Hide
Werner Guttmann added a comment -

I just think I am closer to fixing this issue. Here's what I am currently able to marshal:

<?xml version="1.0" encoding="UTF-8"?>
<party xmlns="http://ACORD.org/Standards/Life/2" id="PaidProducerGUID1">
    <PartyTypeCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tc="1"
        xsi:nil="true" />
    <GovtID>000000000</GovtID>
    <GovtIDTC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tc="11"
        xsi:nil="true" />
    <Person>
        <FirstName>Andy</FirstName>
        <MiddleName>S</MiddleName>
        <LastName>Roddick</LastName>
        <Prefix>Mr.</Prefix>
    </Person>
</party>

Having said that, I'd like to see the XML schema for the corresponding <party> element first. Is there a nillable being used ?

Show
Werner Guttmann added a comment - I just think I am closer to fixing this issue. Here's what I am currently able to marshal:
<?xml version="1.0" encoding="UTF-8"?>
<party xmlns="http://ACORD.org/Standards/Life/2" id="PaidProducerGUID1">
    <PartyTypeCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tc="1"
        xsi:nil="true" />
    <GovtID>000000000</GovtID>
    <GovtIDTC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tc="11"
        xsi:nil="true" />
    <Person>
        <FirstName>Andy</FirstName>
        <MiddleName>S</MiddleName>
        <LastName>Roddick</LastName>
        <Prefix>Mr.</Prefix>
    </Person>
</party>
Having said that, I'd like to see the XML schema for the corresponding <party> element first. Is there a nillable being used ?
Hide
Tausif Farooqi added a comment -

Here as an excerpt of the schema that contains the definition of the <party> element. If you need more details then I can upload the whole schema (a set of 8 xsd files and a total size of 2.15 mb).

Regards,

Tausif

Show
Tausif Farooqi added a comment - Here as an excerpt of the schema that contains the definition of the <party> element. If you need more details then I can upload the whole schema (a set of 8 xsd files and a total size of 2.15 mb). Regards, Tausif
Hide
Tausif Farooqi added a comment -

Hi Werner, was the last attachment (schema excerpt) helpful? It will be great if you can let me know when you think you can fix this problem.

Thanks,

Tausif

Show
Tausif Farooqi added a comment - Hi Werner, was the last attachment (schema excerpt) helpful? It will be great if you can let me know when you think you can fix this problem. Thanks, Tausif
Hide
Werner Guttmann added a comment -

Updated patch for review. Please have a look at the XML document instance shown above. If that output is acceptable, I will commit this patch.

Show
Werner Guttmann added a comment - Updated patch for review. Please have a look at the XML document instance shown above. If that output is acceptable, I will commit this patch.
Hide
Tausif Farooqi added a comment -

This does not work as it fails schema validation due to the extra "xsi" attributes (marked in red) that have been added. Is it possible to get it without those attributes?

<?xml version="1.0" encoding="UTF-8"?>
<party xmlns="http://ACORD.org/Standards/Life/2" id="PaidProducerGUID1">
<PartyTypeCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tc="1" xsi:nil="true" />
<GovtID>000000000</GovtID>
<GovtIDTC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tc="11" xsi:nil="true" />
<Person>
<FirstName>Andy</FirstName>
<MiddleName>S</MiddleName>
<LastName>Roddick</LastName>
<Prefix>Mr.</Prefix>
</Person>
</party>

Show
Tausif Farooqi added a comment - This does not work as it fails schema validation due to the extra "xsi" attributes (marked in red) that have been added. Is it possible to get it without those attributes? <?xml version="1.0" encoding="UTF-8"?> <party xmlns="http://ACORD.org/Standards/Life/2" id="PaidProducerGUID1"> <PartyTypeCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tc="1" xsi:nil="true" /> <GovtID>000000000</GovtID> <GovtIDTC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tc="11" xsi:nil="true" /> <Person> <FirstName>Andy</FirstName> <MiddleName>S</MiddleName> <LastName>Roddick</LastName> <Prefix>Mr.</Prefix> </Person> </party>
Hide
Werner Guttmann added a comment -

Hmm, not sure. But doesn't your last request actually contradict your mapping of those elements in question ? In the mapping file, you are declaring those attributes to be 'nillable' (much in the same way this could be done in an XML schema). As such, I'd expect these elements to be there.

Having said that, I will have a look why these attributes era emitted even when you set setSuppressXSITypes() to true.

Show
Werner Guttmann added a comment - Hmm, not sure. But doesn't your last request actually contradict your mapping of those elements in question ? In the mapping file, you are declaring those attributes to be 'nillable' (much in the same way this could be done in an XML schema). As such, I'd expect these elements to be there. Having said that, I will have a look why these attributes era emitted even when you set setSuppressXSITypes() to true.
Hide
Werner Guttmann added a comment -

Updated patch, as I have added to so suppress xsi:* content for nillable elements as well, is the corresponding flag is set.

Show
Werner Guttmann added a comment - Updated patch, as I have added to so suppress xsi:* content for nillable elements as well, is the corresponding flag is set.
Hide
Werner Guttmann added a comment -

With that last change I am now able to marshal as follows:

<?xml version="1.0" encoding="UTF-8"?>
<party xmlns="http://ACORD.org/Standards/Life/2" id="PaidProducerGUID1">
    <PartyTypeCode tc="1"/>
    <GovtID>000000000</GovtID>
    <GovtIDTC tc="11"/>
    <Person>
        <FirstName>Andy</FirstName>
        <MiddleName>S</MiddleName>
        <LastName>Roddick</LastName>
        <Prefix>Mr.</Prefix>
    </Person>
</party>

if and if the Marshaller is configured to suppress XSI type related information.

Show
Werner Guttmann added a comment - With that last change I am now able to marshal as follows:
<?xml version="1.0" encoding="UTF-8"?>
<party xmlns="http://ACORD.org/Standards/Life/2" id="PaidProducerGUID1">
    <PartyTypeCode tc="1"/>
    <GovtID>000000000</GovtID>
    <GovtIDTC tc="11"/>
    <Person>
        <FirstName>Andy</FirstName>
        <MiddleName>S</MiddleName>
        <LastName>Roddick</LastName>
        <Prefix>Mr.</Prefix>
    </Person>
</party>
if and if the Marshaller is configured to suppress XSI type related information.
Hide
Werner Guttmann added a comment -

Updated patch, which was necessary to make the CTF test suite run successfully.

Show
Werner Guttmann added a comment - Updated patch, which was necessary to make the CTF test suite run successfully.

People

Vote (3)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: