Skip to content
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

FindPlaceFromQueryRequest isn't correctly serialized #377

Open
kimonmeier opened this issue Oct 9, 2024 · 1 comment
Open

FindPlaceFromQueryRequest isn't correctly serialized #377

kimonmeier opened this issue Oct 9, 2024 · 1 comment

Comments

@kimonmeier
Copy link

Hello

Im currently implementig the places service and while trying to query for places an exception got triggered. Somehow i can't really solve it. I has something todo with the FindPlaceFromQueryRequest and the LocationBias, which isn't correctly serialiazed. Is there something wrong on my side, configuration wise?

Kind Regards

Kimon Meier

Code-Example:

@using GoogleMapsComponents
@using GoogleMapsComponents.Maps
@using GoogleMapsComponents.Maps.Places
@inject IJSRuntime JS

<GoogleMap @ref="@_map" OnAfterInit="OnAfterMapInit" Options="@_mapOptions" Id="map"></GoogleMap>
@code {
    private GoogleMap _map = default!;
    private MapOptions _mapOptions = default!;
    private PlacesService placeService = default!;


    private async Task OnAfterMapInit()
    {
        var module = await JS.InvokeAsync<IJSObjectReference>("import", "./Components/Maps/LocationPicker.razor.js");
        await module.InvokeVoidAsync("addCenterMaker");

        this.placeService = await PlacesService.CreateAsync(this._map.JsRuntime, _map.InteropObject);
    }

    protected override void OnInitialized()
    {
        _mapOptions = new MapOptions()
            {
                Zoom = 13,
                Center = new LatLngLiteral()
                {
                    Lat = 13.505892,
                    Lng = 100.8162
                },
                MapTypeId = MapTypeId.Roadmap
            };
    }

    public async Task SearchPlace(string search)
    {
        var response = await this.placeService.FindPlaceFromQuery(new FindPlaceFromQueryRequest()
            {
                Fields = ["name", "geometry"],
                Query = search,
                LocationBias = null
            });

        if (response?.Results?.Geometry?.Location is null)
        {
            return;
        }

        await _map.InteropObject.SetCenter(response.Results.Geometry.Location);

        this.StateHasChanged();
    }

    public async Task SetCenter(double latitude, double longitude)
    {
        await _map.InteropObject.SetCenter(new LatLngLiteral(latitude, longitude));
    }

    public Task<LatLngLiteral> GetCenter()
    {
        return _map.InteropObject.GetCenter();
    }
}

Exception:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Cannot convert GoogleMapsComponents.Maps.Places.LocationBias The unsupported member type is located on type 'System.Object'. Path: $.
System.NotSupportedException: Cannot convert GoogleMapsComponents.Maps.Places.LocationBias The unsupported member type is located on type 'System.Object'. Path: $.
 ---> System.NotSupportedException: Cannot convert GoogleMapsComponents.Maps.Places.LocationBias
   at GoogleMapsComponents.Serialization.OneOfConverterFactory.CreateConverter(Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverterFactory.GetConverterInternal(Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializerOptions.ExpandConverterFactory(JsonConverter converter, Type typeToConvert)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetConverterForType(Type typeToConvert, JsonSerializerOptions options, Boolean resolveJsonConverterAttribute)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateJsonTypeInfo(Type type, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type)
   at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context)
--- End of stack trace from previous location ---
   at System.Text.Json.JsonSerializerOptions.CachingContext.CacheEntry.GetResult()
   at System.Text.Json.JsonSerializerOptions.CachingContext.GetOrAddTypeInfo(Type type, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type type, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.JsonSerializerOptions.TryGetPolymorphicTypeInfoForRootType(Object rootValue, JsonTypeInfo& polymorphicTypeInfo)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Serialize(Utf8JsonWriter writer, Object& rootValue, Object rootValueBoxed)
   at System.Text.Json.JsonSerializer.WriteString[Object](Object& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[Object](Object value, JsonSerializerOptions options)
   at GoogleMapsComponents.Helper.SerializeObject(Object obj)
   at GoogleMapsComponents.Helper.<>c__DisplayClass8_0.<MakeArgJsFriendly>b__0(Object arg)
   at System.Linq.Enumerable.SelectArrayIterator`2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Text.Json.Serialization.Converters.IEnumerableDefaultConverter`2[[System.Linq.Enumerable.SelectArrayIterator`2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Linq, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnWriteResume(Utf8JsonWriter writer, SelectArrayIterator`2 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonCollectionConverter`2[[System.Linq.Enumerable.SelectArrayIterator`2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Linq, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter writer, SelectArrayIterator`2 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Linq.Enumerable.SelectArrayIterator`2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Linq, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].TryWrite(Utf8JsonWriter writer, SelectArrayIterator`2& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Linq.Enumerable.SelectArrayIterator`2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Linq, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].TryWriteAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Object& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.ArrayConverter`2[[System.Object[], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnWriteResume(Utf8JsonWriter writer, Object[] array, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonCollectionConverter`2[[System.Object[], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter writer, Object[] value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object[], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object[], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, NotSupportedException ex)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object[], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Object[], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Serialize(Utf8JsonWriter writer, Object[]& rootValue, Object rootValueBoxed)
   at System.Text.Json.JsonSerializer.WriteString[Object[]](Object[]& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[Object[]](Object[] value, JsonSerializerOptions options)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[PlaceResponse](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[GoogleMapsComponents.Maps.Places.PlaceResponse, GoogleMapsComponents, Version=4.7.14.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
   at GoogleMapsComponents.Helper.<MyInvokeAsync>d__10`1[[GoogleMapsComponents.Maps.Places.PlaceResponse, GoogleMapsComponents, Version=4.7.14.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
   at GoogleMapsComponents.Maps.Places.PlacesService.FindPlaceFromQuery(FindPlaceFromQueryRequest request)
   at Streckenbuch.Client.Components.Maps.LocationPicker.SearchPlace(String search) in C:\Users\Lucky\source\repos\Streckenbuch\Streckenbuch.Client\Components\Maps\LocationPicker.razor:line 37
   at Streckenbuch.Client.Components.Dialogs.CreateSignal.changeSearch(String search) in C:\Users\Lucky\source\repos\Streckenbuch\Streckenbuch.Client\Components\Dialogs\CreateSignal.razor:line 97
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at MudBlazor.MudBaseInput`1.<SetTextAsync>d__182[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at MudBlazor.MudBaseInput`1.<SetValueAsync>d__191[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at MudBlazor.MudBaseInput`1.<SetTextAsync>d__182[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at MudBlazor.MudInput`1.<OnChange>d__16[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
@valentasm1
Copy link
Collaborator

LocationBias is only class which implements OneOfBase. Could be that functionality was lost after migration to System.Text.Json
Second probably it is workaround (solution) to write like this

public OneOf<LatLngLiteral, string>? LocationBias { get; set; }

Problem that that implements 5 types which i think 3 is max. Which is in OneOfConverterFactory

LocationBias : OneOfBase<LatLngLiteral, LatLngBounds, LatLngBoundsLiteral, Circle, string>

Probably easiest solution would be find which 3 params works in most cases. O harder write serializer for 5. There are examples so probably doable.
Another problem that it is resolved in promise which could couse some testing for right solution (i could be wrong)

Here is my findings. Hard to promise deadline. This is very rare. For sure this year :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants