Skip to content

Places: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 408 column 36 path $.result.secondary_opening_hours #906

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

Open
MattWilliams89 opened this issue Apr 12, 2023 · 7 comments · May be fixed by #1024
Assignees
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@MattWilliams89
Copy link

Environment details

OS type and version:
Gradle JDK: jbr-17, 17.0.6
Kotlin JVM: 1.8.0

Library version and other environment information:
com.google.maps:google-maps-services:2.2.0

Running on Ktor server v 2.2.3

Steps to reproduce

  1. Make a call to PlacesApi.placeDetails with placeId ChIJTSQM7Smze0gR627zU4Cvkn4

Code example

return try {
            val response = PlacesApi.placeDetails(GoogleApiClient.context, id).await()
        } catch (e: Throwable) {
            PlacesDetailClientResponse.Error
        }

Stack trace

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 408 column 36 path $.result.secondary_opening_hours

Following these steps will guarantee the quickest resolution possible.

Thanks!

@MattWilliams89 MattWilliams89 added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 12, 2023
@wangela
Copy link
Member

wangela commented Apr 12, 2023

If you would like to upvote the priority of this issue, please comment below or react with 👍 so we can see what is popular when we triage.

@MattWilliams89 Thank you for opening this issue. 🙏
Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

@deansg
Copy link

deansg commented Apr 13, 2023

I have received the same issue when using Java 17, and sending a request for place with id ChIJhbDp64aLGGAR5ywd2IRem7Q

According to the official API documentation here, the secondary_opening_hours field is an Array, which seems to be the cause of the problem

@tomag
Copy link

tomag commented Apr 30, 2023

I bypassed this bug by excluding the secondary_opening_hours field -

        PlaceDetailsRequest request = PlacesApi.placeDetails(geoApiContext, placeId);
        
        request.fields(Arrays.stream(PlaceDetailsRequest.FieldMask.values())
                .filter(x -> x != PlaceDetailsRequest.FieldMask.SECONDARY_OPENING_HOURS)
                .toArray(PlaceDetailsRequest.FieldMask[]::new));

        PlaceDetails response = request.await();

@asloup
Copy link

asloup commented Aug 5, 2023

Here's the same thing in Kotlin if anybody needs it:

        val request = PlacesApi.placeDetails(geoApiContext, placeId)
        val fields = HashSet<PlaceDetailsRequest.FieldMask>()
        fields.addAll(PlaceDetailsRequest.FieldMask.values())
        fields.remove(PlaceDetailsRequest.FieldMask.SECONDARY_OPENING_HOURS)
        request.fields(*fields.toTypedArray())
        val placeDetails: PlaceDetails? = try {
            request.await()
        } catch (e: Exception) {
            println("refreshPlaces - Google Places SDK exception - PlacesApi.placeDetails() - placeId = ${placeId}, error = ${e.message}")
        }

@Osiris-Team
Copy link

This is a json response parsing issue of the google library and should be fixed ASAP! That something like this is open for over 2 years should be unacceptable.

@tel05
Copy link

tel05 commented Apr 14, 2025

I also ran into this issue when using PlacesApi.placeDetails(...). The JsonSyntaxException seems to be caused by the secondary_opening_hours field being returned as an array instead of an object in some responses.

My workaround was to explicitly only request the fields I needed, which excluded secondary_opening_hours entirely and helped reduce the size of the API response as well:

PlaceDetails placeDetails = PlacesApi.placeDetails(context, result.placeId)
    .fields(
        FieldMask.PLACE_ID,
        FieldMask.NAME,
        FieldMask.FORMATTED_ADDRESS,
        FieldMask.FORMATTED_PHONE_NUMBER,
        FieldMask.RATING,
        FieldMask.PRICE_LEVEL,
        FieldMask.GEOMETRY
    )
    .await();

This approach avoids the field altogether and ensures you're not requesting more data than necessary.

@Osiris-Team
Copy link

@MattWilliams89 do you have something else besides the placeId? Because its expired. Or anyone else got a store/company/place where this happens that I can test? I am working on a PR to fix this.

Osiris-Team added a commit to Osiris-Team/google-maps-services-java that referenced this issue Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants