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

fix: keep nil values during (de)serialization #14127

Merged
merged 1 commit into from
Nov 21, 2024
Merged

Conversation

mirkoSekulic
Copy link
Collaborator

@mirkoSekulic mirkoSekulic commented Nov 21, 2024

Description

Sets IsNullable = true to in XmlElement attribute for reference properties if they are defined as nillable in xsd.

Known limitations

Since we're using c# model, when desiralizing XML and serializing it back back, we can't always reproduce the same same XML.

Example

According to xsd schema:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema attributeFormDefault="unqualified"
            elementFormDefault="qualified"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <xsd:element name="root" type="SampleType" />

  <xsd:complexType name="SampleType">
    <xsd:all>
      <xsd:element name="refElement" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="1"/>
    </xsd:all>
  </xsd:complexType>
</xsd:schema>

following XML is valid since minOccurs is set to "0":

<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</root>

But when deserializing and serializing it back we'll produce following XML:

<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <refElement xsi:nil="true" />
</root>

Since the node type is string, functionally XMLs will be equivalent.

Related Issue(s)

Altinn/app-lib-dotnet#911

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

@github-actions github-actions bot added area/data-modeling Area: Related to data models - e.g. create, edit, use data models. solution/studio/designer Issues related to the Altinn Studio Designer solution. quality/testing Tests that are missing, needs to be created or could be improved. skip-releasenotes Issues that do not make sense to list in our release notes backend labels Nov 21, 2024
@mirkoSekulic mirkoSekulic force-pushed the feature/xsd-nill-fix branch 3 times, most recently from 7103f49 to 15a2537 Compare November 21, 2024 12:27
@mirkoSekulic mirkoSekulic removed the skip-releasenotes Issues that do not make sense to list in our release notes label Nov 21, 2024
@mirkoSekulic mirkoSekulic self-assigned this Nov 21, 2024
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.31%. Comparing base (498673f) to head (91b054f).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14127   +/-   ##
=======================================
  Coverage   95.31%   95.31%           
=======================================
  Files        1776     1776           
  Lines       23130    23130           
  Branches     2687     2687           
=======================================
  Hits        22046    22046           
  Misses        835      835           
  Partials      249      249           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@mirkoSekulic mirkoSekulic added the skip-manual-testing PRs that do not need to be tested manually label Nov 21, 2024
@mirkoSekulic mirkoSekulic merged commit 2664fed into main Nov 21, 2024
24 checks passed
@mirkoSekulic mirkoSekulic deleted the feature/xsd-nill-fix branch November 21, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/data-modeling Area: Related to data models - e.g. create, edit, use data models. backend quality/testing Tests that are missing, needs to be created or could be improved. skip-manual-testing PRs that do not need to be tested manually solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-core
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants