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

Serializing enums / reserializing file not 1:1 #183

Closed
shinji144 opened this issue Feb 24, 2021 · 1 comment
Closed

Serializing enums / reserializing file not 1:1 #183

shinji144 opened this issue Feb 24, 2021 · 1 comment

Comments

@shinji144
Copy link

shinji144 commented Feb 24, 2021

Hi @cleftheris,

I've followed the tutorial to serialize/deserialize, using the provided sample file "tradacoms.utilitybill.edi". Deserializing that file provides me a POCO wherein the VatRateCategoryCode gets set to L. However, serializing the same POCO using same grammar yields me a vastly different .edi file compared to the original- and the enum is serialized to its integer equivalent instead of the text.

var grammar = EdiGrammar.NewTradacoms();
var interchange = default(Interchange);

using (var stream = new StreamReader(@"C:\edi testing\tradacoms.utilitybill.edi"))
{
	interchange = new EdiSerializer().Deserialize<Interchange>(stream, grammar);
}

using (var tw = new StreamWriter(File.Open(@"C:\edi testing\tradacoms UtilityBill test1.edi", FileMode.Create)))
{
	using (var twEDI = new EdiTextWriter(tw, grammar))
	{
		new EdiSerializer().Serialize(twEDI, interchange);
	}
}

Why does the enum get serialized as an integer? And why does the reserialized file look dramatically different from the sample?

Thanks!

@cleftheris
Copy link
Contributor

Hi @shinji144 and thanks for your interenst in Edi.Net.

The reason behind the different serialization behavior has todo with the sample.

First of all this usecase shows how someone needing to read an Edi transmission could decide to deserialize characters as well as letters into CLR enums. This feature unfortunately does not work bothways at the moment. It is however a nice enhancement since we could infer the serialization preference from the Picture (format) on the value attribute and decide whether we need to convert to the numeric counterpart underneath (which is the default behavior) or use the name instead.

On the other hand there is no complete parity between the sample nodels and the transmission. In other words models may be incomplete and ignore parts of the data hence the difference in serialized output. The example is meant to showcase the power that the library has in mappind edi to a more dotnet friendly poco class. In case you need to have a one to one parity you need to tweak the example models to suit your needs.

eddyrodrigues added a commit to eddyrodrigues/EDI.Net that referenced this issue Mar 2, 2024
When setting an alphanumeric picture to X(n), then automatically its gonna
translate to Enum Name, not the integer.
Also, two test cases were provided in EdiTextWriterTests.cs.
This Implementation need to be analyzed because of changes in the ConvertUtils.cs, maybe we need to change de approach to some code
that Add Function not change the function.
This can be addressed to Issue indice-co#183
cleftheris pushed a commit that referenced this issue May 24, 2024
* #Feature - Writer limits the amount of chars baseada on Alphanumeric Picture Kind #198

Strict Approach should be set by using GRAMMAR.SetStrictAlphanumericCharLimit(strictAlphanumericCharLimit) function

* Update EdiGrammar.cs

#FIX - StrictAlphanumericCharLimit options under EdiWriter class

* Update EdiTextWriter.cs

#FIX - StrictAlphanumericCharLimit options under EdiWriter class

* Update EdiWriter.cs

#FIX - StrictAlphanumericCharLimit options under EdiWriter class

* Update IEdiGrammar.cs

#FIX - StrictAlphanumericCharLimit options under EdiWriter class

* Update IEdiGrammar.cs

#FIX - StrictAlphanumericCharLimit options under EdiWriter class

* Update EdiTextWriterTests.cs

#FIX - StrictAlphanumericCharLimit options under EdiWriter class

* #Add - Writes Enum as Text when Alphanumeric Picture is Provided

When setting an alphanumeric picture to X(n), then automatically its gonna
translate to Enum Name, not the integer.
Also, two test cases were provided in EdiTextWriterTests.cs.
This Implementation need to be analyzed because of changes in the ConvertUtils.cs, maybe we need to change de approach to some code
that Add Function not change the function.
This can be addressed to Issue #183
cleftheris added a commit that referenced this issue May 24, 2024
Double segment serialization when using wildcard paths #235
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants