In SoapUI Pro Current date and time - no longer working
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In SoapUI Pro Current date and time - no longer working
After a .net upgrade my code for calculating the current date and time no longer works. The below worked fine before with the below
${= new Date().format('yyyy-MM-dd HH:mm:ss.SSSSS Z')}
but now I get the error
The JSON value could not be converted to System.DateTime. Path: $.occurredOn | LineNumber: 26 | BytePositionInLine: 51.
Can anyone offer some solution please?
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey @Alleyn
try ${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date())} instead
ta
rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @richie
Thanks for replyin - unfortunately it'll still same error being returned
'0x0D' is invalid within a JSON string. The string should be correctly escaped. Path: $.occurredOn | LineNumber:
26 | BytePositionInLine: 35.
Might just get the value from a Groovy script instead and pass it in and see how that works.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey @Alleyn
There must be something else going on. A lot of people found they're use of that date() method failing about a year ago and I thought the method had been deprecated in the jre or I think readyapi! moved to openJDK or something like that and so everyone needed to use a different method going forward.
I started using the following at that point:
${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date())}
and the following is completely overkill, but you could try this which also generates curr sysdatetime
${=import java.text.SimpleDateFormat; Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -0); new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(cal.getTime());}
HOWEVER - I suspect the second option won't help either as it still uses the SimpleDateFormat() & Date() methods like the previous option.
What version of ReadyAPI are you using? Also - I didn't understand the significance of upgrading the .net - why should this make a difference to ReadyAPI as it's Java.....???
nice one
rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rich,
Thanks for the reply - ignore the .net comment! I was getting that crossed with another issue I was working at the time.
I get the below error with ${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date())}
"occurredOn" : "startup failed:
Script1.groovy: 1: unexpected char: '\' @ line 1, column 32.
new java.text.SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss\").format(new Date()) ^
org.codehaus.groovy.syntax.SyntaxException: unexpected char: '\' @ line 1, column 32.
In the end I just used the following to me get quickly going - not sure if it's the best solution but it works for me. I had to create a Groovy script and then just reference it.
def CurrentYearTime = use( groovy.time.TimeCategory ) { new Date()}.format("yyyy-MM-dd'T'HH:mm")
testRunner.testCase.setPropertyValue( "CurrentYearTime", CurrentYearTime )
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So weird! It looks like it's parsing and escaping your double quotes and then moaning cos it doesnt like the escaping!
I like your work around!
Cheers,
Rich
