indice-co / EDI.Net

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

Deserializing EDIFACT to XML #232

Closed GingerNinjaa closed 2 years ago

GingerNinjaa commented 2 years ago

Hi, I have a case in with i reacive EDIFACT APPERAK message and i need to convert it to XML. The XML shoul keep the structural convencion lika a edifact.

<SG1>
    <DOC>
      ...
    </DOC>
</SG1>

My class look like this image

And this is working when I want to deserialize file to C# object. When I want to serialize this to XML i reacive below output. As you can see it dont contain segment. How I can manage that? I need to create second class in order to serialize it corectly?

image

cleftheris commented 2 years ago

I have not tried this myself but an idea as a workaround to make this work:

Try and create a subclass of the DOC segment like XMLDoc and put that as a readonly property inside the SG1 class only for xml/json. Try to populate the prop via getter lazy instantiation. Then use XMLIgnore on the SG2 C506 as well as any other component properties that would mess up the nesting level using overrides/hide of base class props.

GingerNinjaa commented 2 years ago

Do you have a eqample how to do it? Im trying my best but I dont know how to implemnt this lazy getter.