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

Deserializing an Edifact file containing an unknown message type #188

Closed
h0gh opened this issue Apr 16, 2021 · 5 comments
Closed

Deserializing an Edifact file containing an unknown message type #188

h0gh opened this issue Apr 16, 2021 · 5 comments
Labels

Comments

@h0gh
Copy link
Contributor

h0gh commented Apr 16, 2021

Hi there,

Is it possible to construct interchange and message objects along the following lines:

public class Interchange {
  public MessageBase Message {get;set;}
}

public abstract class MessageBase { ... }

[EdiMessage, EdiCondition("IFTMIN", "UNH/2/0")
public class IftminMessage : MessageBase { ... }

[EdiMessage, EdiCondition("INVOIC", "UNH/2/0")
public class InvoicMessage : MessageBase { ... }

So that I can deserialize a file with any type of message in it, without knowing which type up front?

Thank you for the great library

@cleftheris
Copy link
Contributor

cleftheris commented Apr 16, 2021

Hi @h0gh and thanks for your interest in EDI.Net.

As I remember it could be possible with some tweaking since this is the way that TRADACOMS works. See here for a sample with multiple message types in the same transmission https://github.com/indice-co/EDI.Net/blob/master/test/indice.Edi.Tests/Models/UtilityBill.cs.

The only problem (missing part) with polymorphism & serialization as far as I can tell is that you will have to introduce some new attribute type that signals the serializer to search for CLR types elsewhere than the current model. There was something similar that existed in wcf, the KnownTypesAttribute .

@h0gh
Copy link
Contributor Author

h0gh commented Apr 16, 2021

Thanks. I don't truly need the inheritance, and I got it working by having N separate adjacent lists of messages for each of the N message types. I had tried this previously, but dismissed it because it caused my program to eat all my memory and crash. This turned out to be because I had an off-by-one error in my Edicondition path. The correct path to the edifact document type is UNH/1/0, not UNH/2/0.

When using the path UNH/2/0, I believe the deserializer gets stuck in an infinite loop in the EdiSerializer.SearchForward method (the do-while in lines 654-665). I can submit a PR with a test exhibiting this behavior if you're interested.

@cleftheris
Copy link
Contributor

cleftheris commented Apr 16, 2021

Hi @h0gh
Yes a test like this is very helpful! Feel free to make a pull request

@cleftheris
Copy link
Contributor

There is a new version that addresses the infinite loop issue. Thanks for your contribution!

@h0gh
Copy link
Contributor Author

h0gh commented May 18, 2021

Thanks!

@h0gh h0gh closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants