Fix localized string converter for reading plugin configuration#694
Fix localized string converter for reading plugin configuration#694ze-dom wants to merge 2 commits intoMUnique:masterfrom
Conversation
Summary of ChangesHello @ze-dom, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug where localized strings within plugin configurations were not being deserialized correctly from JSON, leading to application startup exceptions and display issues in the AdminPanel. The changes ensure that Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses an issue with deserializing LocalizedString from plugin configurations by updating the LocalizedStringJsonConverter to handle object formats. It also adds [JsonIgnore] attributes to derived properties and modifies UI components for nullable LocalizedString support. My review highlights two areas for improvement: the JSON converter's parsing logic could be more robust, and the LocalizedStringFieldBuilder's type checking may be too restrictive. The suggestions provided aim to enhance the resilience and correctness of these components.
| if (reader.TokenType == JsonTokenType.StartObject) | ||
| { | ||
| reader.Read(); | ||
| if (reader.TokenType == JsonTokenType.PropertyName) | ||
| { | ||
| reader.Read(); | ||
| var value = reader.GetString(); | ||
| reader.Read(); // consume the end of object | ||
| return new LocalizedString(value); | ||
| } | ||
| } |
There was a problem hiding this comment.
The current implementation for reading a LocalizedString from a JSON object is fragile. It assumes the object contains exactly one property and doesn't verify its name. This could lead to incorrect deserialization or runtime errors if the JSON structure has additional properties or a different property name. A more robust approach using JsonDocument would ensure the entire object is consumed correctly and allow for explicit property checking.
if (reader.TokenType == JsonTokenType.StartObject)
{
using var jsonDoc = JsonDocument.ParseValue(ref reader);
if (jsonDoc.RootElement.TryGetProperty("Value", out var valueElement) && valueElement.ValueKind == JsonValueKind.String)
{
return new LocalizedString(valueElement.GetString());
}
}|
|
||
| /// <inheritdoc/> | ||
| public bool CanBuildComponent(PropertyInfo propertyInfo) => propertyInfo.PropertyType == typeof(LocalizedString); | ||
| public bool CanBuildComponent(PropertyInfo propertyInfo) => propertyInfo.PropertyType == typeof(LocalizedString?); |
There was a problem hiding this comment.
This change restricts the component builder to only handle nullable LocalizedString properties (LocalizedString?). This might be a regression if you have non-nullable LocalizedString properties that should be rendered by this builder. To support both nullable and non-nullable types, the check should be broadened.
public bool CanBuildComponent(PropertyInfo propertyInfo) => Nullable.GetUnderlyingType(propertyInfo.PropertyType) == typeof(LocalizedString) || propertyInfo.PropertyType == typeof(LocalizedString);|
Thanks! I somehow didn't see this problems during testing, but I can reproduce it when I reinitialize the database. |
After the multilanguage support PR, I was having exceptions when starting up the DB. It turned out

LocalizedStrings withinPlugInConfiguration.CustomConfigurationcouldn't be read by theLocalizedStringJsonConverterbecause those are kept as objects within the JSON data:The
LocalizedStrings were also not showing up on the AdminPanel's edit modal.