indice-co / indice-co/EDI.Net

Multiple repeated elements within a single segment

Open
#272 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
490
Forks
173
PR merge metrics
No merged PRs in 30d

Description

I'm working with a segment **PFD** that has **multiple** repeated elements within the segment and also repeated elements within repeated elements.

All the examples I have found seem to only have a single repeated element within a segment. I have other segments like that and they work.

The issue is specifically with **multiple** repeated elements in the same segment.

![image](https://github.com/user-attachments/assets/057e42cb-d257-4a94-9f48-7c23d43560e7)

I have been trying many combinations trying to get these to serialize onto a **single** PFD segment, but it always seems to split them off into separate PFD segments.

Even if I need to do the Seat Characteristics as 5 individual `EdiValue` each (not repeated), there are still multiple repeated elements that I haven't been able to get to serialize into a single PFD segment

Is there a way to accomplish this or any workaround method to achieve it?

What I thought I should do is like this:
```csharp
[EdiPath("PFD/1/8..*")]
public PFD_SeatCharacteristic[] SeatCharacteristics { get; set; }
```
...

Then this:
```csharp
[EdiPath("PFD/6..*")]
public PFD_SeatDetail[] SeatDetails { get; set; }

[EdiPath("PFD/7..*")]
public PFD_SeatDefinition[] SeatDefinitions { get; set; }
```

But that results in
```
System.InvalidOperationException: 'Failed to compare two elements in the array.'
InvalidCastException: Cannot convert the fragment value "6..*" to an Index. Must be a positive integer
```

I have been trying different models, but here is a trimmed down one:
```csharp
//PFD
public class Interchange_PFD
{
public PFD PFD { get; set; }
}

[EdiSegment, EdiPath("PFD")]
public class PFD
{
[EdiValue(Path = "PFD/0/0")]
public string PFD_01A_SpecificSeat { get; set; }

[EdiValue(Path = "PFD/0/1")]
public string PFD_01B_FreeSeatingReference { get; set; }

[EdiValue(Path = "PFD/1/0")]
public string PFD_02A_NoSmokingIndicator { get; set; }

[EdiValue(Path = "PFD/1/1")]
public string PFD_02B_CabinClassDesignator { get; set; }

[EdiValue(Path = "PFD/1/2")]
public string PFD_02C_CabinClassNumber { get; set; }

[EdiValue(Path = "PFD/1/3")]
public string PFD_02D_FreeTextCabinClassZone { get; set; }

[EdiValue(Path = "PFD/1/4")]
public string PFD_02E_SegmentAirportOfDeparture { get; set; }

[EdiValue(Path = "PFD/1/5")]
public string PFD_02F_SegmentAirportOfArrival { get; set; }

[EdiValue(Path = "PFD/1/6")]
public string PFD_02G_EquipmentCode { get; set; }

[EdiValue(Path = "PFD/1/7")]
public string PFD_02H_SeatRequestFullfilledIndicator { get; set; }

[EdiPath("PFD/1/8..*")]
public PFD_SeatCharacteristic[] SeatCharacteristics { get; set; }

[EdiValue(Path = "PFD/2/0")]
public string PFD_07_PaxIdForBPPrint { get; set; }

[EdiValue(Path = "PFD/2/1")]
public string PFD_07_InfantIdForBPPrint { get; set; }

[EdiValue(Path = "PFD/3/0")]
public string PFD_08_IssueReissueBoardingPass { get; set; }

[EdiValue(Path = "PFD/4/0")]
public string PFD_09_BarcodeForBoardingPass { get; set; }

[EdiValue(Path = "PFD/5/0")]
public string PFD_10_PaxPriorityInformation { get; set; }

[EdiPath("PFD/6..*")]
public PFD_SeatDetail[] SeatDetails { get; set; }

[EdiPath("PFD/7..*")]
public PFD_SeatDefinition[] SeatDefinitions { get; set; }
}

[EdiElement]
public class PFD_SeatCharacteristic
{
[EdiValue(Path = "PFD/1/8")]
public string PFD_02I_SeatCharacteristics { get; set; }
}

[EdiElement]
public class PFD_SeatDetail
{
[EdiValue(Path = "*/*/0")]
public string PFD_11A_SpecificSeat { get; set; }

[EdiValue(Path = "*/*/1")]
public string PFD_11B_FreeSeatingReference { get; set; }
}

[EdiElement]
public class PFD_SeatDefinition
{
[EdiValue(Path = "*/*/0")]
public string PFD_12A_NoSmokingIndicator { get; set; }

[EdiValue(Path = "*/*/1")]
public string PFD_12B_CabinClassDesignator { get; set; }

[EdiValue(Path = "*/*/2")]
public string PFD_12C_CabinClassNumber { get; set; }

[EdiValue(Path = "*/*/3")]
public string PFD_12D_FreeTextCabinClassZone { get; set; }

[EdiValue(Path = "*/*/4")]
public string PFD_12E_SegmentAirportOfDeparture { get; set; }

[EdiValue(Path = "*/*/5")]
public string PFD_12F_SegmentAirportOfArrival { get; set; }

[EdiValue(Path = "*/*/6")]
public string PFD_12G_EquipmentCode { get; set; }

[EdiValue(Path = "*/*/7")]
public string PFD_12H_SeatRequestFullfilledIndicator { get; set; }

[EdiValue(Path = "*/*/8")]
public string PFD_12I_SeatCharacteristics { get; set; }

[EdiValue(Path = "*/*/9")]
public string PFD_12J_SeatCharacteristics { get; set; }

[EdiValue(Path = "*/*/10")]
public string PFD_12K_SeatCharacteristics { get; set; }

[EdiValue(Path = "*/*/11")]
public string PFD_12L_SeatCharacteristics { get; set; }

[EdiValue(Path = "*/*/12")]
public string PFD_12M_SeatCharacteristics { get; set; }
}
```

```csharp
var interchange = new Interchange_PFD()
{
PFD = new PFD
{
PFD_01A_SpecificSeat = "12C",
PFD_02A_NoSmokingIndicator = "N",
PFD_02B_CabinClassDesignator = "M",
PFD_02C_CabinClassNumber = "3",
PFD_02E_SegmentAirportOfDeparture = "FRA",
PFD_02F_SegmentAirportOfArrival = "MEX",
PFD_02G_EquipmentCode = "744",
SeatCharacteristics = new PFD_SeatCharacteristic []
{
new PFD_SeatCharacteristic {
PFD_02I_SeatCharacteristics = "Y"
},
new PFD_SeatCharacteristic {
PFD_02I_SeatCharacteristics = "Z"
}
},
PFD_07_PaxIdForBPPrint = "12",
PFD_10_PaxPriorityInformation = "M/M",
SeatDetails = new PFD_SeatDetail[] {
new PFD_SeatDetail {
PFD_11A_SpecificSeat = "01X"
},
new PFD_SeatDetail {
PFD_11A_SpecificSeat = "02X"
}
},
SeatDefinitions = new PFD_SeatDefinition[] {
new PFD_SeatDefinition {
PFD_12A_NoSmokingIndicator = "A"
},
new PFD_SeatDefinition {
PFD_12A_NoSmokingIndicator = "B"
}
}
}
};

var output = new StringBuilder();
var grammar = EdiGrammar.NewEdiFact();
using (var writer = new EdiTextWriter(new StringWriter(output), grammar))
{
new EdiSerializer() { EnableCompression = true }.Serialize(writer, interchange);
Debug.Write(output);
}
```

Again, the goal is to get these to serialize all into a single PFD segment

Is this possible by any means?

Thank you

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the supplied Interchange_PFD example using EdiSerializer and EdiTextWriter, then inspect how wildcard EdiPath arrays are grouped during serialization. The change is complete when repeated seat characteristics, details, and definitions serialize into one PFD segment without the shown InvalidCastException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.