3 Replies Latest reply on Jan 29, 2019 4:02 PM by rareddy

    org.json.JSONException: Misshaped element

    lhoskins

      Hi All, I need some help with JSON error on Wildfly.

       

      I am using RESTEASY with JAX-RS.  The preview of the JSON data outputs as expected but when I run from Teiid Swagger or the url directly from the browser I get the following error:

      </style></head><body><div class="header"><div class="error-div"></div><div class="error-text-div">Error processing request</div></div><div class="label">Context Path:</div><div class="value">/category</div><br/><div class="label">Servlet Path:</div><div class="value">/CategoryREST</div><br/><div class="label">Path Info:</div><div class="value">/json/category</div><br/><div class="label">Query String:</div><div class="value">null</div><br/><div class="label">Stack Trace:</div><div class="value"></div><br/><pre>org.jboss.resteasy.spi.UnhandledException: java.lang.RuntimeException: org.json.JSONException: Misshaped element. at character 298 of {"agg0":[{"category_description":"Current Year's Actuals","category_id":"ACTUAL"},{"category_description":"Adjustment for Budget input","category_id":"ADJUSTMENT"},{"category_description":"Current Year's Budget","category_id":"BUDGET"},{"category_description":"Forecast","category_id":"FORECAST"}]} at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:78) at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:222) at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:179)

       

      The json string was validated through a third party application. I'm using the following select statement:

      BEGIN

      SELECT JSONOBJECT(JSONARRAY_AGG(JSONOBJECT(Category.category.category_description, Category.category.category_id))) AS Json FROM Category.category;

      END

       

      Results from the SQL Results pane

       

      REST Properties

        • 1. Re: org.json.JSONException: Misshaped element
          rareddy

          what is the version of the Teiid server you are using?

           

          I suspect at the time of implementing the rest services, Teiid did not have any way to generate JSON, but only XML. But if the user is asking for JSON Teiid expected the procedure to return the XML which got auto-converted to JSON. Now that JSON can be returned the check can be removed and return the payload as is. Which I believe is a bug. Can you add JIRA so that we can fix it?

           

          Also I would like to know how you were deploying the VDB, are you generating the WAR file and deploying it, or you are just deploying the VDB and an implicit war file is generated for you? as there are two separate implementations of this layer, maybe I can point to the other one to see the same problem exists or not/

           

          For a workaround, you could produce an XML document instead of JSON to get past the error.

          • 2. Re: org.json.JSONException: Misshaped element
            lhoskins

            Hi Ramesh,

            Yes, I am implementing the rest service. I do not have any problem with the XML functions outputs to a browser. It's only JSON functions that errors out in the browser but runs successful in the Teiid Designer. I will submit a JIRA to remove the check.

             

            I am deploying the war file through the REST EASY Generator using JAX-RS.  We are trying the workaround using XML instead for now.

             

            Appreciate your prompt response.

             

            Thanks!

             

            Leonard

            • 3. Re: org.json.JSONException: Misshaped element
              rareddy

              You can also try to see if this works REST Service Through VDB · GitBook  as this is more sustainable and we are trying to keep this supported in future like for example [TEIIDSB-4] Provide rest access with SpringBoot - JBoss Issue Tracker