-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding collection properties makes enum generic type nullable #796
Comments
Note, the de/serialization code (in FileName.Serialization.cs) is also expecting it to be nullable, even though the array value is not nor was it when the generator was generating the properties: void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (IgnoreScripts != null && IgnoreScripts.Any())
{
writer.WritePropertyName("ignoreScripts");
writer.WriteStartArray();
foreach (var item in IgnoreScripts)
{
writer.WriteStringValue(item.Value.ToSerialString());
}
writer.WriteEndArray();
}
// ...
internal static CjkBigramTokenFilter DeserializeCjkBigramTokenFilter(JsonElement element)
{
IList<CjkBigramTokenFilterScripts?> ignoreScripts = default;
bool? outputUnigrams = default;
string odataType = default;
string name = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("ignoreScripts"))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
List<CjkBigramTokenFilterScripts?> array = new List<CjkBigramTokenFilterScripts?>();
foreach (var item in property.Value.EnumerateArray())
{
if (item.ValueKind == JsonValueKind.Null)
{
array.Add(null);
}
else
{
array.Add(item.GetString().ToCjkBigramTokenFilterScripts());
}
}
ignoreScripts = array;
continue;
} |
Note also, that if I change my property definition to use writer.WriteStringValue(item.Value.ToString()); If I remove my property declaration entirely and let the generator do it all, the code is correct throughout, indicating this isn't a regression, but some corner case bug with customized properties: // generated property:
public IList<TokenFilterName> TokenFilters { get; set; }
// constructor
internal AnalyzeRequest(string text, LexicalAnalyzerName? analyzer, LexicalTokenizerName? tokenizer, IList<TokenFilterName> tokenFilters, IList<string> charFilters)
{
Text = text;
Analyzer = analyzer;
Tokenizer = tokenizer;
TokenFilters = tokenFilters;
CharFilters = charFilters ?? new List<string>();
} |
For Azure/azure-sdk-for-net#11712 I moved collection properties to a customized class with
[CodeGenMember(EmptyAsUndefined = true, Initialize = true)]
; however, this now causes the generator to declare the internal serialization constructor asIEnumerable<T?>
- nullable, despite these types being non-nullable:This ends up looking like:
CjkBigramTokenFilterScripts
is an enum withx-nullable
asfalse
, and even instantiation of a list gets it right, but the parameter should make the type nullable - the parameter itself could be, but since it's a reference type it naturally is already.I can work around the problem by changing my declaration, but that is not the shape of the API we want. As such, this is blocking.
The text was updated successfully, but these errors were encountered: