Getting an error when using `java.time.ZonedDateTime` in ScriptRunner Script Console

Hamza Nazeer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 8, 2022

I am getting the following error when I use `java.time.ZonedDateTime` in ScriptRunner Script Console.

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.ZonedDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: com.adaptavist.sr.cloud.output.ScriptExecutionOutput["result"]) 
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1300)
at com.fasterxml.jackson.databind.ser.impl.UnsupportedTypeSerializer.serialize(UnsupportedTypeSerializer.java:35)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeWithType(BeanSerializerBase.java:657)
at com.fasterxml.jackson.databind.ser.impl.TypeWrappedSerializer.serialize(TypeWrappedSerializer.java:32)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1518)
at com.fasterxml.jackson.databind.ObjectWriter._writeValueAndClose(ObjectWriter.java:1219)
at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:1086)

 

The issue can be reproduced with a simple script below,

import java.time.ZonedDateTime

def time = ZonedDateTime.now()

return time

 

I have seen many examples from people using ZonedDateTimem but unfortunately it does not work for me. Even the ScriptRunner Cloud recommends using java.time for time calculations instead of Date.

It would be really helpful if you can help me to resolve the issue.

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 16, 2023

Hi @Hamza Nazeer

Could you change the approach you are trying to retrieve the Current Date by adding it to a log parameter as shown below:-

import java.time.ZonedDateTime


logger.warn "====>>>${ZonedDateTime.now()}"

 This approach is working as shown in the screenshot below:-

test.png

I am suggesting this approach because it ScriptRunner in Jira could not directly able to read the value of the ZoneDateTime.now() and returns an exception.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events