Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing derived types with multiple namespaces doesn't work for single-package style models #520

Closed
untereiner opened this issue Jun 11, 2021 · 6 comments
Labels
enhancement New feature or request known

Comments

@untereiner
Copy link

untereiner commented Jun 11, 2021

Hello,

I have an issue when I parse an xml into the classes previously generated.
My error is:
xsdata.exceptions.ParserError: Unknown property {http://www.energistics.org/energyml/data/resqmlv2}AbstractIntegerArray:{http://www.energistics.org/energyml/data/commonv2}NullValue

That is a simplified version of the schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:complexType name="AbstractIntegerArray" abstract="true">    
  </xs:complexType>

  <xs:complexType name="IntegerExternalArray">
    <xs:extension base="AbstractIntegerArray">
    </xs:extension>
    <xs:element name="NullValue" type="xs:long">
    </xs:element>
  </xs:complexType>

  <xs:complexType name="TriangulatedSetRepresentation">
    <xs:element name="SupportingRepresentationNodes" type="AbstractIntegerArray" minOccurs="1" maxOccurs="1">                            
    </xs:element>
  </xs:complexType>
</xs:schema>

And here is a sample xml file

<?xml version="1.0" encoding="UTF-8"?>
<TriangulatedSetRepresentation>
		<SupportingRepresentationNodes xsi:type="IntegerExternalArray">
                <NullValue xsi:type="xsd:long">2147483647</NullValue>
        </SupportingRepresentationNodes>
</TriangulatedSetRepresentation>

I think the parser expects an AbstractIntegerArray and do not know what to do with the NullValue.
I am using master branch

@untereiner
Copy link
Author

Here is the complete example just in case.
Usage: python ./test.py TriangulatedSetRepresentation_17004506-f1db-4d34-8d66-efd6b4b15d73.xml
complete_example.zip

@tefra
Copy link
Owner

tefra commented Jun 11, 2021

The single package structure style doesn't work very well for derived types (aka xsi:type="eml23:IntegerExternalArray") when more than one namespaces is involved. docs

If you notice on top of each module xsdata adds the source namespace the classes/types were originally declared.
Unfortunately the single package structure automatically bundles all types under the same namespace, which is extracted from the first class of the module.

I suggest to switch to another structure style, if you picked the single package due to circular imports give the new clusters style a try.

Suggestions:

  1. Generate the source namespace as a meta property when there is more than one namespace involved per module
  2. Raise an exception during codegen for this case if the above doesn't work.

@tefra tefra added known enhancement New feature or request labels Jun 11, 2021
@tefra tefra changed the title parsing misleading Parsing derived types with multiple namespaces doesn't work for single-package style models Jun 11, 2021
@untereiner
Copy link
Author

The clusters style is working fine thank you.
I am maybe wrong but I am trying to round trip between xml and json.
I can deserialize an xml file and serialize it into a json string.
But when I try to deserialize this json string (to serialize it to xml) I have an issue similar to the mentioned above:

xsdata/xsdata/formats/dataclass/parsers/json.py", line 131, in bind_dataclass
    raise ParserError(f"Unknown property {clazz.__qualname__}.{key}")
xsdata.exceptions.ParserError: Unknown property AbstractIntegerArray.NullValue

@tefra
Copy link
Owner

tefra commented Jun 12, 2021

Roundtrips between json and xml also don't work all the time with derived/abstract types, you see the information xsi:type is lost between transfers.

We could make the parser attempt all possible classes, but that will also have some misses, in case more than one subclass fits the json properties.

@untereiner
Copy link
Author

One another option could be to serialize into badgerFish json

@tefra tefra closed this as completed in 54ebc76 Jun 14, 2021
@tefra
Copy link
Owner

tefra commented Jun 14, 2021

One another option could be to serialize into badgerFish json

Will continue this one here #523

Original issue was resolved in #525, the generator now will check for multiple namespaces in the module and will generate the target namespace per type instead on top for all module classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request known
Projects
None yet
Development

No branches or pull requests

2 participants