Skip to content

[Bug]: Cannot serialise LocalDate when sending API post request #1865

@ScrubbyXIV

Description

@ScrubbyXIV

Version

1.56.0

Steps to reproduce

Hello,

When trying to send a post request like requestContext.post( someUrl, RequestOptions.create().setData(somePOJOWithLocalDateProperty) that has a POJO with a LocalDate property, gson is unable to serialize the POJO and throws the following exception:

com.google.gson.JsonIOException: Failed making field 'java.time.LocalDate#year' accessible; either increase its visibility or write a custom TypeAdapter for its declaring type.
See https://github.com/google/gson/blob/main/Troubleshooting.md#reflection-inaccessible

at com.google.gson.internal.reflect.ReflectionHelper.makeAccessible(ReflectionHelper.java:76)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:389)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:165)
at com.google.gson.Gson.getAdapter(Gson.java:627)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:205)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:396)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:165)
at com.google.gson.Gson.getAdapter(Gson.java:627)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:205)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:396)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:165)
at com.google.gson.Gson.getAdapter(Gson.java:627)
at com.google.gson.Gson.toJson(Gson.java:927)
at com.google.gson.Gson.toJson(Gson.java:898)
at com.google.gson.Gson.toJson(Gson.java:847)
at com.google.gson.Gson.toJson(Gson.java:824)
at com.microsoft.playwright.impl.APIRequestContextImpl.fetchImpl(APIRequestContextImpl.java:122)
at com.microsoft.playwright.impl.APIRequestContextImpl.fetch(APIRequestContextImpl.java:66)
at com.microsoft.playwright.impl.APIRequestContextImpl.post(APIRequestContextImpl.java:208)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final int java.time.LocalDate.year accessible: module java.base does not "opens java.time" to unnamed module @87aac27
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at com.google.gson.internal.reflect.ReflectionHelper.makeAccessible(ReflectionHelper.java:68)
... 22 more

I went through the code and saw, that there's type adapters for Date and LocalDateTime, but none for LocalDate.

Expected behavior

I'd expect LocalDate to be supported by the Gson Serialization Utility by default.

Actual behavior

Any tests with POJOs containing LocalDate properties are failing.
Other tests are running fine.

Additional context

No response

Environment

  • OS: Windows 10
  • Browser: any
  • Java: 17.0.10-tem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions