-
Notifications
You must be signed in to change notification settings - Fork 99
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
Incorrect Serialization of Enums #293
Comments
control is not positioned as TOP_LEFT but as BOTTOM_CENTER. this is different bug. Not related to serialization. Solved with #281 |
I believe it is another bug. Upon running the Blazor Server Demo and examining the MapLegendPage, I observed that its intended position, TOP_LEFT, is not reflected in the actual placement; it appears at BOTTOM_CENTER instead. During debugging, I noticed that the addControl method in the objectManager is receiving "topLeft" as the enum value. However, this doesn't seem to match any case in the switch statement, causing it to revert to the default case of BOTTOM_CENTER. I initially noticed this in my current application when trying to position the control on RIGHT_CENTER. using System.Threading.Tasks;
using GoogleMapsComponents;
using GoogleMapsComponents.Maps;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace ServerSideDemo.Pages;
public partial class MapLegendPage
{
private GoogleMap map1;
private MapOptions mapOptions;
[Inject] private IJSRuntime jsRuntime { get; set; }
protected ElementReference legendReference { get; set; }
protected override void OnInitialized()
{
mapOptions = new MapOptions()
{
Zoom = 13,
Center = new LatLngLiteral()
{
Lat = 13.505892,
Lng = 100.8162
},
MapTypeId = MapTypeId.Roadmap
};
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await jsRuntime.InvokeAsync<object>("initMapLegend");
}
}
private async Task AfterMapInit()
{
await map1.InteropObject.AddControl(ControlPosition.TopLeft, legendReference);
}
} |
Please register new issue then. One bug one issue. |
I can do that, I just thought that since it was a caused by the serialization it was one bigger issue, that control position was just one case where I noticed it. But I understand that it might be a separate thing and could be fixed with less of a code change. |
No need PR. Just sample of code how it should is enough since change is very small |
…d_using_enummember Fix bug #293 Incorrect serialization of Enums
I merger PR. It dont work. I tried for 30min and give up. Reverted. |
Sry my bad, I should have tested it more. I will update the code so that it works and thoroughly test it. |
I've been digging into this, and experimenting with a different custom serializer for enums. |
Sharing knowledge is always great. Thank you. |
Description
The BlazorGoogleMaps library does not always use the
EnumMember
attribute when serializing enums to JSON. This causes map controls to not be correctly positioned on the map. For instance, the enumTOP_LEFT
gets serialized astopLeft
, leading to incorrect behavior.Additional Details
JsonStringEnumConverterEx
class for the correct behavior but it is not used on theControlPosition
enum.Helper.cs
had serialization that was not adding the converter to theJsonSerializerOptions
. This might have been affecting more than theControlPosition
enum.Expected Behavior
EnumMember
attribute.Current Behavior
EnumMember
attribute.Steps to Reproduce
TOP_LEFT
.TOP_LEFT
but asBOTTOM_CENTER
.Suggested Fix
EnumMember
attribute for enums.JsonStringEnumConverterEx
class for theControlPosition
enum and other enums missing the converter.Helper.cs
to include the converter inJsonSerializerOptions
.Additional Information
This serialization issue significantly impacts the functionality and usability of the BlazorGoogleMaps library, as controls and other enum-dependent features do not behave as expected.
Example of Incorrect Code
Potential Impact
Contribution and Proposed Changes
I am willing to contribute to the resolution of this issue and will submit a pull request with the necessary changes. The proposed changes include updating the JsonConverter attribute to respect the
EnumMember
attribute in enum serialization and correctly implementing theJsonStringEnumConverterEx
in all the enums and add the converter inHelper.cs
.Thank you for your attention to this matter.
The text was updated successfully, but these errors were encountered: