indice-co / EDI.Net

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

Serialization problem: Excess Trailing Data Element Delimiter(s) #99

Closed smoorsausje closed 6 years ago

smoorsausje commented 6 years ago

Hello,

Thank you for this awesome module. It has really helped us a lot in deserializing our EDIFACT files.

Now we want to use it to serialize as well and are sadly running into an issue.

I have a CONTRL message that I want to serialize and they have to be certified by an external party. Their certification application says we have excessive trailing data element delimiters.

For example in the UNB Segment:

2: UNB+UNOC:3+1234567891011:14+0123456789101:14+110618:1324+11++SCL++++'
--
10611:Excess Trailing Data Element Delimiter(s) after UNB07 (D.E. 0026) at col. 62{Severity:Error - Type:General}

This is the POCO I use for this segment:

[EdiSegment, EdiPath("UNB")]
public class UNB
{
    [EdiValue("X(4)", Mandatory = true, Path = "UNB/0")]
    public string SyntaxIdentifier { get; set; }

    [EdiValue("9(1)", Path = "UNB/0/1", Mandatory = true)]
    public int SyntaxVersion { get; set; }

    [EdiValue("X(35)", Path = "UNB/1/0", Mandatory = true)]
    public string SenderId { get; set; }

    [EdiValue("X(4)", Path = "UNB/1/1", Mandatory = false)]
    public string SenderIdQualifier { get; set; }

    [EdiValue("X(14)", Path = "UNB/1/2", Mandatory = false)]
    public string ReverseRoutingAddress { get; set; }

    [EdiValue("X(35)", Path = "UNB/2/0", Mandatory = true)]
    public string RecipientId { get; set; }

    [EdiValue("X(4)", Path = "UNB/2/1", Mandatory = false)]
    public string RecipientIdQualifier { get; set; }

    [EdiValue("X(14)", Path = "UNB/2/2", Mandatory = false)]
    public string RoutingAddress { get; set; }

    [EdiValue("9(6)", Path = "UNB/3/0", Format = "ddMMyy", Description = "Date of Preparation")]
    [EdiValue("9(4)", Path = "UNB/3/1", Format = "HHmm", Description = "Time or Prep")]
    public DateTime DateOfPreparation { get; set; }

    [EdiValue("X(14)", Path = "UNB/4", Mandatory = true)]
    public string ControlReference { get; set; }

    [EdiValue("X(14)", Path = "UNB/5/0", Mandatory = false)]
    public string RecipientReference { get; set; }

    [EdiValue("X(2)", Path = "UNB/5/1", Mandatory = false)]
    public string RecipientReferenceQualifier { get; set; }

    [EdiValue("X(14)", Path = "UNB/6", Mandatory = false)]
    public string ApplicationReference { get; set; }

    [EdiValue("X(1)", Path = "UNB/7", Mandatory = false)]
    public string ProcessingPriorityCode { get; set; }

    [EdiValue("9(1)", Path = "UNB/8", Mandatory = false)]
    public int? AcknowledgementRequest { get; set; }

    [EdiValue("X(35)", Path = "UNB/9", Mandatory = false)]
    public string CommunicationsAgreementId { get; set; }

    [EdiValue("X(1)", Path = "UNB/10", Mandatory = false)]
    public string TestIndicator { get; set; }
}

And this is the input:

new UNB
{
    SyntaxIdentifier = "UNOC",
    SyntaxVersion = 3,
    SenderId = "1234567891011",
    SenderIdQualifier = "14",
    RecipientId = "0123456789101",
    RecipientIdQualifier = "14",
    DateOfPreparation = DateTime.UtcNow,
    ControlReference = "11",
    ApplicationReference = "SCL"
}

I am using this code for testing:

var grammar = EdiGrammar.NewEdiFact();
var interchange = new Interchange<CONTRL>
{
    Header = new UNB
    {
        ...
    }
    ...
};
var stringBuilder = new StringBuilder();
using (var writer = new StringWriter(stringBuilder))
using (var ediWriter = new EdiTextWriter(writer, grammar))
{
    new EdiSerializer().Serialize(ediWriter, interchange);
    var contrl = stringBuilder.ToString();
}

From what I could find out, the ++++ behind the "SCL" at the end of the segment is not supposed to be there. But as you can see I have set "Mandatory = false", so I expected it not to put those there.

Am I doing something wrong by any chance?

Thank you very much for your help.

Kind regards, smoorsausje

cleftheris commented 6 years ago

This is related to compression. I already have an open issue #48 regarding this feature, but I did not realize that this was causing errors in transmissions. I will make this a priority

smoorsausje commented 6 years ago

Yeah, it seems they are quite strict about this in our particular case.

Thanks a lot, I'll be looking forward to the feature! :)