full-evening-54933
06/28/2023, 1:37 PMthis.client = RudderAnalytics.builder(apiKey)
.setDataPlaneUrl(dataPlaneUrl)
.flushQueueSize(10)
.log(RudderStackLog())
.build()
Because of that I can’t provide custom TypeAdapter to correctly map “Instant” Java class. Following method throws an error:
public int messageSizeInBytes(Message message) {
Gson gson = getGsonInstance();
String stringifiedMessage = gson.toJson(message); <<--- Can't serialize Instant
int sizeInBytes = stringifiedMessage.getBytes(ENCODING).length;
return sizeInBytes;
}
Exception:
com.google.gson.JsonIOException: Failed making field 'java.time.Instant#seconds' accessible; either change its visibility or write a custom TypeAdapter for its declaring type
Is there any way to workaround the problem? 🤔
BTW I’m using Java SDK from Kotlin code.full-evening-54933
06/29/2023, 7:41 AMkind-carpenter-27609
06/29/2023, 7:42 AMnarrow-wolf-10290
06/29/2023, 1:40 PMfull-evening-54933
06/30/2023, 6:34 AM{
...
val message = TrackMessage.builder("api_requested")
.userId(userContext.userId)
.properties(
mapOf(
"serviceName" to serviceName,
"request" to mapOf(
"url" to requestContext.url,
"queryName" to requestContext.queryName,
"queryArguments" to requestContext.queryArgs,
),
"error" to errorValue,
),
)
this.client.enqueue(message)
}
Where requestContext.queryArgs is Map<String, Any> . And one of the fields in the structure is Instant .
Now I made a workaround to just parse requestContext.queryArgs POJO -> JSON -> POJO by custom ObjectMapper (Jackson) . It works because “unsupported” Instant class is parsed to String.
...
"queryArguments" to cleanupFromUnsupportedTypes(requestContext.queryArgs)
...
private fun cleanupFromUnsupportedTypes(data: Map<String, Any>): Map<*, *> = objectMapper.readValue(objectMapper.writeValueAsString(data))
Of course it is not an ideal solution, so would be good if it would be possible to just provide own GSON client or “stringify” method implementation 🙂narrow-wolf-10290
07/24/2023, 9:57 AM