indice-co / EDI.Net

EDI Serializer/Deserializer. Supports EDIFact, X12 and TRADACOMS formats
MIT License
447 stars 170 forks source link

EdiCondition not working to RFF+CR #257

Open sukleinkauf opened 5 months ago

sukleinkauf commented 5 months ago

Thank you for putting in the work and making this library available.

I am trying to parse an EDIFACT 01B file and I am having troubles in constructing my custom classes to read an EDIFACT file. I am trying to map the RFF+CR with no success. I am brand new on EDIFACT, so possible I am doing something wrong here.

LIN+00010++000000000060325004:IN'
IMD+++:::VALVE,TEST,FULLPORT,1IN,SS,FLG'
QTY+21:9.000'
DTM+50:20240422:102'
DTM+2:20240422:102'
MOA+203:81'
GIN+BN+FG125'
PRI+INF'
CUX+2:AUD:9'
RFF+CR:S/F, P4, TEST'
RFF+AEU:TEST_Exw W AUS-S/F'
RFF+WS:MAIN'
PAC+++EA'
TDT+20++G4'
LIN+00020++000000000060367095:IN'
IMD+++:::VALVE,GATE,KNIFE,200MM,CS,WAFER'
QTY+21:11.000'
DTM+50:20240819:102'
DTM+2:20240819:102'
MOA+203:44'
GIN+BN+200NB ANSI150'
PRI+INF'
CUX+2:AUD:9'
RFF+CR:TEST,TEST,s/f,p4'
RFF+AEU:Test_Exw W AUS-S/F'
RFF+WS:MAIN'
PAC+++EA'
TDT+20++G4'

My code:

      [EdiSegment, EdiSegmentGroup("LIN", SequenceEnd = "TDT")]
      public class LineItem
      {
          [EdiValue("X(1)", Path = "LIN/0/0")]
          public string LineNumber { get; set; }

          [EdiValue("9(3)", Path = "QTY/0/1")]
          public string Qty { get; set; }

          [EdiValue("9(3)", Path = "LIN/1/0")]
          public string Code { get; set; }

          [EdiValue("9(3)", Path = "LIN/2/0")]
          public string Unit { get; set; }

          [EdiValue("9(3)", Path = "LIN/2/1")]
          public string Type { get; set; }

          [EdiCondition("2", Path = "DTM/0/0")]
          public Date ActualDeliveryData { get; set; } //ATA

          [EdiCondition("50", Path = "DTM/0/0")]
          public Date ExpectedShipDate { get; set; } //ETD

          public PriceDetails Prices { get; set; }

          [EdiValue("X(256)", Path = "IMD/2/3")]
          public string ItemDescription { get; set; }

          [EdiCondition("CR", Path = "RFF/0")]
          public Reference OtherReferences { get; set; }

      }

Thank you

cleftheris commented 4 months ago

Hi @sukleinkauf it seems to me you are using the simple version of defining a segment group. The one with sequence end would not work well in your scenario (actually its not recommended for most cases). It usually works for simplistic quick deserialization scenarios. These usually map only few component values flat on the segment group class (In your case that would be LIN).

That said you should go with the explicit declaration of the SegmentGroups attribute by specifying all segment tags involved in the group on the same level (Segment groups can also be nested).

Check these other questions regarding segment groups https://github.com/indice-co/EDI.Net/issues/214

Also you can find interesting examples in the tests project