Test Data Manager

 View Only
  • 1.  Swagger Java Client throws JSON exception

    Posted Oct 18, 2019 11:22 AM

    Hello, 


    We have generated an Swagger Java Client. using the Swagger UI JSON files.

    Example shown below

    java -jar swagger-codegen-cli-2.4.8.jar generate -i "swagger.json" -l java -o CATDMTestManager1 -apiPackage=CATDMAPI

    Through this generated Client we have managed to successfully login and get an authorization token.

    However when we make subsequent calls we are getting some exceptions.  This is where we need help with.


    Case 1 - Issue with De-serialisation an offset date.

    =====

    PiiData response = api.getAJobsPiiDataForOneTableUsingGET1(authorization, projectId, versionId, table, false);

    Result


    xception in thread "main" org.threeten.bp.format.DateTimeParseException: Text '1568825756733' could not be parsed at index 0

        at org.threeten.bp.format.DateTimeFormatter.parseToBuilder(DateTimeFormatter.java:1587)

        at org.threeten.bp.format.DateTimeFormatter.parse(DateTimeFormatter.java:1491)

        at org.threeten.bp.OffsetDateTime.parse(OffsetDateTime.java:359)

        at io.swagger.client.JSON$OffsetDateTimeTypeAdapter.read(JSON.java:219)

        at io.swagger.client.JSON$OffsetDateTimeTypeAdapter.read(JSON.java:182)


    Case 2 - Issue with Array De-Serialization of size 1.

    =======

    List<PiiDataColumn> PiiDataColumns =api.getAJobsPiiDataForOneTableAndColumnsUsingGET1(authorization, projectId, versionId, table, null, 10000, false, false);


    Result

    Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

        at com.google.gson.Gson.fromJson(Gson.java:939)

        at com.google.gson.Gson.fromJson(Gson.java:892)

        at com.google.gson.Gson.fromJson(Gson.java:841)

    looking forward to getting solution for these.



    thanks,

    Jaimini



  • 2.  RE: Swagger Java Client throws JSON exception
    Best Answer

    Posted Jan 31, 2020 05:48 AM
    Hi Jaimini,

    I'm guessing it is the null value which is causing this, I've stumbled upon this before even in the portal swagger-ui you can see this error.

    What does help here is using the developer tools of the browser and look at the calls being made when you do the action in the portal. Look closely at the request bodies being send. The portal is using the same API and the developer tools are very very handy to figure out what is needed in the request body. Do not trust the swagger-ui documentation on request bodies, most of the properties are stating optional but are often required.

    Best regards,
    Peter