I'm trying to parse the response from a Firestore trigger that runs when there is a change to the database. I'm following this documentation: https://cloud.google.com/functions/docs/calling/cloud-firestore. In this case, just any new entries, which falls underneath the "value" attribute. I've attempted to use BackgroundFunction because DocumentEventData contains all the fields in that object but that throws an error with the serialization of the date.
public class myFunction implements BackgroundFunction<DocumentEventData> {
private static final Gson gson = new Gson();
@Override
public void accept(DocumentEventData payload, Context context) throws Exception {
System.out.println("Event Received: " + payload);
}
}
I get the following error:
Failed to execute com.ford.avllc.taas.statecoordinator.StateChangeProcessor
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
Expected BEGIN_OBJECT but was STRING at path $.value.createTime
Is there a way to parse this via the BackgroundFunction type without having to use an ObjectMapper with specific properties?
I say that because the workaround I'm doing is using an object mapper with a RawBackgroundFunction which returns a String, which I then convert via ObjectMapper to DocumentEventData.
Edit: Ironically following Google's documentation word by word leads to the same result using GSON.