firely-cql-sdk
firely-cql-sdk copied to clipboard
592 valuetuple objects created from cql tuple types are missing field names
Very early draft. Demonstrates the base interfaces for tuples, some examples what generated tuples would look like TupleA and TupleB, and tests to show how they are can be copied from each other, string formatting, and equality.
The generated tuples TupleA and TupleB would not go into the Tuples package, instead that's the way they would be generated as nested types as part of a library
There is also a second idea called a CqlTuple<T> which takes a static list of property names, and a tuple.
public static readonly string[] PersonProperties = ["Name", "ID", "Addresses"];
public static readonly string[] AddressProperties = ["AddressType", "Street", "City", "Country"];
[TestMethod]
public void TestJsonSerializationNested()
{
CqlTuple<(string? AddressType, string? Street, string? City, string? Country)> homeAddr =
new(AddressProperties, ( "Home", "Joe Street", "Springfield", "USA"));
CqlTuple<(string? AddressType, string? Street, string? City, string? Country)> workAddr =
new(AddressProperties, ("Work", "Sue Street", "Jumpville", "Canada"));
CqlTuple<(string? Name, int? ID, CqlTuple<(string? AddressType, string? Street, string? City, string? Country)>[]? Addressses)> person =
new(PersonProperties, ("John", 10, [homeAddr, workAddr]));
var serializedJson = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true});
Assert.AreEqual(
"""
{
"Name": "John",
"ID": 10,
"Addresses": [
{
"AddressType": "Home",
"Street": "Joe Street",
"City": "Springfield",
"Country": "USA"
},
{
"AddressType": "Work",
"Street": "Sue Street",
"City": "Jumpville",
"Country": "Canada"
}
]
}
""", serializedJson);
}