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

Question: How to serialize with several segments with the same name and different qualifiers #179

Open
maussi opened this issue Nov 29, 2020 · 2 comments
Labels

Comments

@maussi
Copy link

maussi commented Nov 29, 2020

(Thank you very much for this helpful library). I am new to EDI tech. Trying to understand the serialization path usage of identical segments with different qualifiers (generating 850 based on X12)
I am following sample from https://github.com/indice-co/EDI.Net/blob/master/test/indice.Edi.Tests/Models/X12_850.cs
As I understand, the REF segment can occur more then once in the EDI structure. Below is simplified problem description :

My goal is to serialize three segments to something like this (each segment has unique qualifier):
REF*A*1~
REF*B*2~
REF*C*3~

Here are examples of corresponding properties (I tried various combinations of Path syntax to better understand them, but still failing)

   	[EdiMessage]
        public class Order
        {
              [EdiValue(Path = "REF/0", Description = "Should result with REF*A")]
              public string VarIdA { get; set; }

              [EdiValue(Path = "REF/1", Description = "Should result with REF*A*1~")]
              public string ValueA { get; set; }

              [EdiValue(Path = "REF/0", Description = "Should result with REF*B")]
              public string VarIdB { get; set; }

              [EdiValue(Path = "REF/1", Description = "Should result with REF*B*2~")]
              public string ValueB { get; set; }

              [EdiValue(Path = "REF/0", Description = "Should result with REF*C")]
              public string VarIdC { get; set; }

              [EdiValue(Path = "REF/1", Description = "Should result with REF*C*3~")]
              public string ValueC { get; set; }
       }

Where assigned values are
VarIdA = "A";
ValueA = "1";
VarIdB = "B";
ValueB = "2";
VarIdC = "C";
ValueC = "3";

The resulting EDI is not what I wanted:


REF*A~
REF*B~
REF*C*1~
REF**2~
REF**3~

With my approach I see that all REF0 are parsed first. Then all REF1 are parsed and the first value from REF1 complements the last REF/0.

So, I understand that paths are relational across all properties with identical segments. No matter how I experimented with paths syntax, I was not successful.

Please, help to understand how paths are constructed and evaluated in scenarios with multiple instances of the same segment.

@cleftheris
Copy link
Contributor

cleftheris commented Nov 30, 2020

You need a container class in order to achieve something like this.
Try with a representing the REF segment like this
The order of the properties is taken into account. Also If you need to support de-serialization you will have to decorate the properties with the EdiCondition attribute.

    [EdiMessage]
    public class Order
    {
          [EdiCondition("A", Path = "REF/0/0")]
          public REF RefA { get; set; }
          [EdiCondition("B", Path = "REF/0/0")]
          public REF RefB { get; set; }
          [EdiCondition("C", Path = "REF/0/0")]
          public REF RefC { get; set; }
    }

    [EdiSegment, EdiPath("REF")]
    public class REF
    {
          [EdiValue(Path = "*/0", Description = "Id part")]
          public string VarId { get; set; }

          [EdiValue(Path = "*/1", Description = "Value part")]
          public string Value { get; set; }
    }

Alternatively you can use a collection of refs inside your message.

    [EdiMessage]
    public class Order
    {
          public List<REF> Refs { get; set; } = new List<REF>();
    }

    [EdiSegment, EdiPath("REF")]
    public class REF
    {
          [EdiValue(Path = "*/0", Description = "Id part")]
          public string VarId { get; set; }

          [EdiValue(Path = "*/1", Description = "Value part")]
          public string Value { get; set; }
    }

A note regarding paths.

  1. Paths are consisted of three parts like so [The segment name]/[The element index]/[The component index]
    In X12 frequently there are almost always single component elements, thus the third part of the path can be ommited since it almost always defaulst to zero 0. This does not mean it is non existent.
  2. Paths can use the wildcard character when livig inside a class so that the same class can be re-used in a different "context" depending on the property EdiPath annotation. For instance this is exceptionally usefull when making use of EdiElement classes.
  3. Paths can use the range nottation 2..5 when binding to collections. For instance this way someone can have some segments or elements bind to a collection property except the first one.

@maussi
Copy link
Author

maussi commented Dec 1, 2020

Thank you. The explanation helped with the current issue and with some others. Thank you for your library.

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