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

Open

Description

@MattWilliams89

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!

Activity

  1. added
    triage meI really want to be triaged.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Apr 12, 2023
  2. wangela commented on Apr 12, 2023

    @wangela
    Member

    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.

  3. deansg commented on Apr 13, 2023

    @deansg

    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

  4. tomag commented on Apr 30, 2023

    @tomag

    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();
    
  5. asloup commented on Aug 5, 2023

    @asloup

    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}")
            }
    
  6. Osiris-Team commented on Apr 10, 2025

    @Osiris-Team

    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.

  7. tel05 commented on Apr 14, 2025

    @tel05

    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.

  8. Osiris-Team commented on Apr 15, 2025

    @Osiris-Team

    @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.

  9. added a commit that references this issue on Apr 15, 2025
    302d42d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions