EDI.Net
EDI.Net copied to clipboard
x12 ISA grammar.ComponentDataElementSeparator not serializing
When serializing an x12
The ISA should be termibnated with a > char
grammar.ComponentDataElementSeparator = '>'
However it is omitted:
ISA*00* *00* *ZZ*DEF *ZZ*ABC *210303*0952*U*00400*000000013*0*T~
It should be:
ISA*00* *00* *ZZ*DEF *ZZ*ABC *210303*0952*U*00400*000000013*0*T*>~
e.g.
Use the PurcahseOrder_850 from the samples
Serialize using:
using (var sw = new StringWriter())
{
using (var ediWriter = new EdiTextWriter(sw, EdiGrammar.NewX12()))
{
var s = new EdiSerializer();
s.Serialize(ediWriter, item);
}
var res = sw.ToString();
return res ;
}
Hi @bobloblawslawblogs this is a known Issue with X12 when serializing. I will investigate a workaround.
Thank you, that would be appreciated! For the moment I am using this very, very rough patch after losing a few hours trying to fix it myself
var res = sw.ToString();
var hack = res.Split(new [] {System.Environment.NewLine }, StringSplitOptions.None );
hack[0] = hack[0].Replace("~", "*>~");
return string.Join(System.Environment.NewLine, hack);
Hello @cleftheris , is there any visibility of a fix? I'm going to be using this for a second EDI provider now, who uses different data element separators. While I can build on the "hack" a clean solution would be preferred σας ευχαριστώ
another hack - but can parameterize the data element separator if needed or just hard code the ">" where separator is used.
public Acknowledgement_997 ParseToObject(string original, string separator)
{
var grammer = EdiGrammar.NewX12();
var interchange = default(Acknowledgement_997);
using (TextReader textReader = new StringReader(original))
{
interchange = new EdiSerializer().Deserialize<Acknowledgement_997>(textReader, grammer);
}
interchange.ISA.ISA16 = interchange.ISA.ISA16 ?? separator ;
return interchange;
}