google-maps-services-java icon indicating copy to clipboard operation
google-maps-services-java copied to clipboard

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

Open MattWilliams89 opened this issue 2 years ago • 7 comments

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 avatar Apr 12 '23 17:04 MattWilliams89

If you would like to upvote the priority of this issue, please comment below or react with :+1: 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.

wangela avatar Apr 12 '23 17:04 wangela

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<OpeningHours>, which seems to be the cause of the problem

deansg avatar Apr 13 '23 20:04 deansg

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();

tomag avatar Apr 30 '23 05:04 tomag

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}")
        }

asloup avatar Aug 05 '23 13:08 asloup