Forum Discussion

Alleyn's avatar
Alleyn
Contributor
4 years ago
Solved

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?

 

  • Hey Alleyn,

    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

5 Replies

  • richie's avatar
    richie
    Community Hero

    Hey Alleyn 

     

    try ${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date())} instead

     

    ta

     

    rich

    • Alleyn's avatar
      Alleyn
      Contributor

      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.

      • richie's avatar
        richie
        Community Hero

        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