From 8e886f4c61c4aeab65c88d115264fb29d42fbd8f Mon Sep 17 00:00:00 2001 From: claudiamurialdo Date: Wed, 19 Nov 2025 20:30:47 -0300 Subject: [PATCH] Fix XML deserialization issue for GXCData --- .../GxClasses/Domain/GxCollections.cs | 16 +- .../Domain/SdtXmlSerializationTest.cs | 13 ++ .../Domain/type_SdtInvoicyretorno.cs | 139 +++++++++++++ .../type_SdtInvoicyretorno_MensagemItem.cs | 183 ++++++++++++++++++ ...oicyretorno_MensagemItem_DocumentosItem.cs | 127 ++++++++++++ .../DotNetCoreUnitTest.csproj | 3 + dotnet/test/DotNetCoreUnitTest/invoicy.xml | 14 ++ 7 files changed, 481 insertions(+), 14 deletions(-) create mode 100644 dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno.cs create mode 100644 dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno_MensagemItem.cs create mode 100644 dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno_MensagemItem_DocumentosItem.cs create mode 100644 dotnet/test/DotNetCoreUnitTest/invoicy.xml diff --git a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs index 3b7a0b396..cb1f74069 100644 --- a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs +++ b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs @@ -2201,11 +2201,7 @@ public override short readxmlcollection(GXXMLReader oReader, string sName, strin return 0; } } -#if !NETCORE - public class GXCData : Object, IXmlSerializable -#else - public class GXCData : Object -#endif + public class GXCData : IXmlSerializable { public string content; @@ -2217,7 +2213,6 @@ public GXCData(string s) { content = s; } -#if !NETCORE public System.Xml.Schema.XmlSchema GetSchema() { return new System.Xml.Schema.XmlSchema(); @@ -2230,13 +2225,8 @@ public void WriteXml(System.Xml.XmlWriter writer) { writer.WriteCData(content); } -#endif } -#if !NETCORE - public class GXXmlRaw : Object, IXmlSerializable -#else - public class GXXmlRaw : Object -#endif + public class GXXmlRaw : IXmlSerializable { public string content; @@ -2248,7 +2238,6 @@ public GXXmlRaw(string s) { content = s; } -#if !NETCORE public System.Xml.Schema.XmlSchema GetSchema() { return new System.Xml.Schema.XmlSchema(); @@ -2261,7 +2250,6 @@ public void WriteXml(System.Xml.XmlWriter writer) { writer.WriteRaw(content); } -#endif } public class GXProperties : NameObjectCollectionBase, IGxJSONSerializable, IGxJSONAble diff --git a/dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs b/dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs index c3dd69419..cff07c18d 100644 --- a/dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs +++ b/dotnet/test/DotNetCoreUnitTest/Domain/SdtXmlSerializationTest.cs @@ -1,3 +1,4 @@ +using System.IO; using GeneXus.Application; using GeneXus.Programs; using Xunit; @@ -25,5 +26,17 @@ public void EmptyValuesDeserializationTest() Assert.True(shouldSerializeField, "Departamento should be serialized since it was assigned during XML deserialization"); } + + [Fact] + public void GXCDataDeserializationTest() + { + GxContext context = new GxContext(); + SdtInvoicyretorno invoice = new SdtInvoicyretorno(context); + string xml = File.ReadAllText("invoicy.xml"); + + invoice.FromXml(xml, null, "Invoicyretorno", "InvoiCy"); + Assert.Contains("40047", invoice.ToJSonString(), System.StringComparison.OrdinalIgnoreCase); + + } } } diff --git a/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno.cs b/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno.cs new file mode 100644 index 000000000..b1588eba4 --- /dev/null +++ b/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno.cs @@ -0,0 +1,139 @@ +/* + File: type_SdtInvoicyretorno + Description: Invoicyretorno + Author: Nemo 🐠 for C# (.NET) version 18.0.13.186668 + Program type: Callable routine + Main DBMS: +*/ +using GeneXus.Application; +using GeneXus.Utils; +using System.Collections; +using System.Xml.Serialization; + + +namespace GeneXus.Programs +{ + [XmlRoot(ElementName="Invoicyretorno")] + [XmlType(TypeName="Invoicyretorno" , Namespace="InvoiCy" )] + public class SdtInvoicyretorno : GxUserType + { + public SdtInvoicyretorno( ) + { + /* Constructor for serialization */ + } + + public SdtInvoicyretorno(IGxContext context) + { + this.context = context; + initialize(); + } + + #region Json + private static Hashtable mapper; + public override string JsonMap(string value) + { + if (mapper == null) + { + mapper = new Hashtable(); + } + return (string)mapper[value]; ; + } + + public override void ToJSON() + { + ToJSON(true) ; + return; + } + + public override void ToJSON(bool includeState) + { + if (gxTv_SdtInvoicyretorno_Mensagem != null) + { + AddObjectProperty("Mensagem", gxTv_SdtInvoicyretorno_Mensagem, false); + } + return; + } + #endregion + + #region Properties + + [SoapElement(ElementName="Mensagem" )] + [XmlArray(ElementName="Mensagem" )] + [XmlArrayItemAttribute(ElementName="MensagemItem" , IsNullable=false )] + public GXBaseCollection gxTpr_Mensagem + { + get { + if ( gxTv_SdtInvoicyretorno_Mensagem == null ) + { + gxTv_SdtInvoicyretorno_Mensagem = new GXBaseCollection( context, "Invoicyretorno.MensagemItem", ""); + } + SetDirty("Mensagem"); + return gxTv_SdtInvoicyretorno_Mensagem; + } + set { + gxTv_SdtInvoicyretorno_Mensagem_N = false; + gxTv_SdtInvoicyretorno_Mensagem = value; + SetDirty("Mensagem"); + } + } + + public void gxTv_SdtInvoicyretorno_Mensagem_SetNull() + { + gxTv_SdtInvoicyretorno_Mensagem_N = true; + gxTv_SdtInvoicyretorno_Mensagem = null; + } + + public bool gxTv_SdtInvoicyretorno_Mensagem_IsNull() + { + return gxTv_SdtInvoicyretorno_Mensagem == null; + } + public bool ShouldSerializegxTpr_Mensagem_GxSimpleCollection_Json() + { + return gxTv_SdtInvoicyretorno_Mensagem != null && gxTv_SdtInvoicyretorno_Mensagem.Count > 0; + + } + + + public override bool ShouldSerializeSdtJson() + { + return ( + ShouldSerializegxTpr_Mensagem_GxSimpleCollection_Json() || + false); + } + + + + #endregion + + #region Static Type Properties + + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo { get { return _typeProps; } set { _typeProps = value; } } + + #endregion + + #region Initialization + + public void initialize( ) + { + gxTv_SdtInvoicyretorno_Mensagem_N = true; + + return ; + } + + + + #endregion + + #region Declaration + + protected bool gxTv_SdtInvoicyretorno_Mensagem_N; + protected GXBaseCollection gxTv_SdtInvoicyretorno_Mensagem = null; + + + + #endregion + } + +} \ No newline at end of file diff --git a/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno_MensagemItem.cs b/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno_MensagemItem.cs new file mode 100644 index 000000000..499d2d143 --- /dev/null +++ b/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno_MensagemItem.cs @@ -0,0 +1,183 @@ +/* + File: type_SdtInvoicyretorno_MensagemItem + Description: Mensagem + Author: Nemo 🐠 for C# (.NET) version 18.0.13.186668 + Program type: Callable routine + Main DBMS: +*/ +using GeneXus.Application; +using GeneXus.Utils; +using System.Collections; +using System.Xml.Serialization; + + +namespace GeneXus.Programs +{ + [XmlRoot(ElementName="Invoicyretorno.MensagemItem")] + [XmlType(TypeName="Invoicyretorno.MensagemItem" , Namespace="InvoiCy" )] + public class SdtInvoicyretorno_MensagemItem : GxUserType + { + public SdtInvoicyretorno_MensagemItem( ) + { + /* Constructor for serialization */ + gxTv_SdtInvoicyretorno_MensagemItem_Descricao = ""; + + } + + public SdtInvoicyretorno_MensagemItem(IGxContext context) + { + this.context = context; + initialize(); + } + + #region Json + private static Hashtable mapper; + public override string JsonMap(string value) + { + if (mapper == null) + { + mapper = new Hashtable(); + } + return (string)mapper[value]; ; + } + + public override void ToJSON() + { + ToJSON(true) ; + return; + } + + public override void ToJSON(bool includeState) + { + AddObjectProperty("Codigo", gxTpr_Codigo, false); + + + AddObjectProperty("Descricao", gxTpr_Descricao, false); + + if (gxTv_SdtInvoicyretorno_MensagemItem_Documentos != null) + { + AddObjectProperty("Documentos", gxTv_SdtInvoicyretorno_MensagemItem_Documentos, false); + } + return; + } + #endregion + + #region Properties + + [SoapElement(ElementName="Codigo")] + [XmlElement(ElementName="Codigo")] + public int gxTpr_Codigo + { + get { + return gxTv_SdtInvoicyretorno_MensagemItem_Codigo; + } + set { + gxTv_SdtInvoicyretorno_MensagemItem_Codigo = value; + SetDirty("Codigo"); + } + } + + + + + [SoapElement(ElementName="Descricao")] + [XmlElement(ElementName="Descricao")] + public string gxTpr_Descricao + { + get { + return gxTv_SdtInvoicyretorno_MensagemItem_Descricao; + } + set { + gxTv_SdtInvoicyretorno_MensagemItem_Descricao = value; + SetDirty("Descricao"); + } + } + + + + + [SoapElement(ElementName="Documentos" )] + [XmlArray(ElementName="Documentos" )] + [XmlArrayItemAttribute(ElementName="DocumentosItem" , IsNullable=false )] + public GXBaseCollection gxTpr_Documentos + { + get { + if ( gxTv_SdtInvoicyretorno_MensagemItem_Documentos == null ) + { + gxTv_SdtInvoicyretorno_MensagemItem_Documentos = new GXBaseCollection( context, "Invoicyretorno.MensagemItem.DocumentosItem", ""); + } + SetDirty("Documentos"); + return gxTv_SdtInvoicyretorno_MensagemItem_Documentos; + } + set { + gxTv_SdtInvoicyretorno_MensagemItem_Documentos_N = false; + gxTv_SdtInvoicyretorno_MensagemItem_Documentos = value; + SetDirty("Documentos"); + } + } + + public void gxTv_SdtInvoicyretorno_MensagemItem_Documentos_SetNull() + { + gxTv_SdtInvoicyretorno_MensagemItem_Documentos_N = true; + gxTv_SdtInvoicyretorno_MensagemItem_Documentos = null; + } + + public bool gxTv_SdtInvoicyretorno_MensagemItem_Documentos_IsNull() + { + return gxTv_SdtInvoicyretorno_MensagemItem_Documentos == null; + } + public bool ShouldSerializegxTpr_Documentos_GxSimpleCollection_Json() + { + return gxTv_SdtInvoicyretorno_MensagemItem_Documentos != null && gxTv_SdtInvoicyretorno_MensagemItem_Documentos.Count > 0; + + } + + + public override bool ShouldSerializeSdtJson() + { + return true; + } + + + + #endregion + + #region Static Type Properties + + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo { get { return _typeProps; } set { _typeProps = value; } } + + #endregion + + #region Initialization + + public void initialize( ) + { + gxTv_SdtInvoicyretorno_MensagemItem_Descricao = ""; + + gxTv_SdtInvoicyretorno_MensagemItem_Documentos_N = true; + + return ; + } + + + + #endregion + + #region Declaration + + protected int gxTv_SdtInvoicyretorno_MensagemItem_Codigo; + + + protected string gxTv_SdtInvoicyretorno_MensagemItem_Descricao; + + protected bool gxTv_SdtInvoicyretorno_MensagemItem_Documentos_N; + protected GXBaseCollection gxTv_SdtInvoicyretorno_MensagemItem_Documentos = null; + + + + #endregion + } + +} \ No newline at end of file diff --git a/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno_MensagemItem_DocumentosItem.cs b/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno_MensagemItem_DocumentosItem.cs new file mode 100644 index 000000000..2d93dfbdc --- /dev/null +++ b/dotnet/test/DotNetCoreUnitTest/Domain/type_SdtInvoicyretorno_MensagemItem_DocumentosItem.cs @@ -0,0 +1,127 @@ +/* + File: type_SdtInvoicyretorno_MensagemItem_DocumentosItem + Description: Documentos + Author: Nemo 🐠 for C# (.NET) version 18.0.13.186668 + Program type: Callable routine + Main DBMS: +*/ +using GeneXus.Application; +using GeneXus.Utils; +using System.Collections; +using System.Xml.Serialization; + + +namespace GeneXus.Programs +{ + [XmlRoot(ElementName = "Invoicyretorno.MensagemItem.DocumentosItem")] + [XmlType(TypeName = "Invoicyretorno.MensagemItem.DocumentosItem", Namespace = "InvoiCy")] + public class SdtInvoicyretorno_MensagemItem_DocumentosItem : GxUserType + { + public SdtInvoicyretorno_MensagemItem_DocumentosItem() + { + /* Constructor for serialization */ + gxTv_SdtInvoicyretorno_MensagemItem_DocumentosItem_Documento = ""; + + } + + public SdtInvoicyretorno_MensagemItem_DocumentosItem(IGxContext context) + { + this.context = context; + initialize(); + } + + #region Json + private static Hashtable mapper; + public override string JsonMap(string value) + { + if (mapper == null) + { + mapper = new Hashtable(); + } + return (string)mapper[value]; ; + } + + public override void ToJSON() + { + ToJSON(true); + return; + } + + public override void ToJSON(bool includeState) + { + AddObjectProperty("Documento", gxTpr_Documento, false); + + return; + } + #endregion + + #region Properties + + [XmlElement(ElementName = "Documento")] + public GXCData gxTpr_Documento_GXCData + { + get + { + return new GXCData(gxTv_SdtInvoicyretorno_MensagemItem_DocumentosItem_Documento); + } + set + { + gxTv_SdtInvoicyretorno_MensagemItem_DocumentosItem_Documento = (string)(value.content); + } + } + [XmlIgnore] + public string gxTpr_Documento + { + get + { + return gxTv_SdtInvoicyretorno_MensagemItem_DocumentosItem_Documento; + } + set + { + gxTv_SdtInvoicyretorno_MensagemItem_DocumentosItem_Documento = value; + SetDirty("Documento"); + } + } + + + + public override bool ShouldSerializeSdtJson() + { + return true; + } + + + + #endregion + + #region Static Type Properties + + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo { get { return _typeProps; } set { _typeProps = value; } } + + #endregion + + #region Initialization + + public void initialize() + { + gxTv_SdtInvoicyretorno_MensagemItem_DocumentosItem_Documento = ""; + return; + } + + + + #endregion + + #region Declaration + + protected string gxTv_SdtInvoicyretorno_MensagemItem_DocumentosItem_Documento; + + + + #endregion + } + + +} \ No newline at end of file diff --git a/dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj b/dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj index 8788115ca..57c940912 100644 --- a/dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj +++ b/dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj @@ -108,6 +108,9 @@ PreserveNewest + + Always + PreserveNewest diff --git a/dotnet/test/DotNetCoreUnitTest/invoicy.xml b/dotnet/test/DotNetCoreUnitTest/invoicy.xml new file mode 100644 index 000000000..5507aa0c4 --- /dev/null +++ b/dotnet/test/DotNetCoreUnitTest/invoicy.xml @@ -0,0 +1,14 @@ + + + + + 100 + Documentos processados + + + NFe400471]]> + + + + +