7 Replies Latest reply on Jan 4, 2016 3:06 AM by lv_levi

    how the Rest War can return json

    lv_levi

      hi everyone,

           I create the Rest service Through VDB and it output as xml,How can I  output an json?  here is demo for rest War settings:

       

       

      QQ截图20151228151413.png

       

      the rest url  and result  as fllows:

      http://localhost:8080/RestPerson/PDSViewMdl/get/03870005

       

      <v_person>

       

      <v_person>

       

       

      <person_id>03870005</person_id>

       

      <name>bob</name>

      <mobile>11111111</mobile>

      </v_person>

      </v_person>


      thanks!


        • 1. Re: how the Rest War can return json
          lv_levi

          BTW, I add the Transformation SQl just like this:


          "BEGIN

            SELECT XMLELEMENT(NAME v_person, XMLAGG(XMLELEMENT(NAME v_person, XMLFOREST(PDSViewMdl.v_person.person_id, PDSViewMdl.v_person.name, PDSViewMdl.v_person.mobile)))) AS result FROM PDSViewMdl.v_person WHERE PDSViewMdl.v_person.person_id = PDSViewMdl.getPerson.person_id;

          END"

           

          how can I add the ContentType=application/json into the up SQL.

           

          levi

          thanks.

          • 2. Re: how the Rest War can return json
            shawkins

            With just the standard REST logic there is no automatic conversion to JSON.  You can change your procedure to use the json function instead - JSON Functions - Teiid 9.0 (draft) - Project Documentation Editor

             

            If you use an OData instead, then the client can choose between JSON and XML/Atom.

            • 3. Re: how the Rest War can return json
              lv_levi

              hi Steven,

                  My problems is how to change the procedure to use json function instead. I try using this just like:

               

              BEGIN

                SELECT XMLELEMENT(NAME v_project, XMLAGG(XMLELEMENT(NAME v_project, XMLFOREST(restProject.v_project.name, restProject.v_project.pid, restProject.v_project.project_code)))) AS result FROM (EXEC invokeHttp(action => 'GET', endpoint => 'http://localhost:8080/projectvdb/restProject/get', headers => JSONOBJECT('application/json' as  "Content-Type"))) AS f, restProject.v_project WHERE restProject.v_project.pid = restProject.getPersonBypid.pid;

              END

               

              the jsonobject is not work here, some json funciton did i missed? BTW,I did not use the OData.

               

              levi

              thanks

              • 4. Re: how the Rest War can return json
                shawkins

                > the jsonobject is not work here, some json funciton did i missed? BTW,I did not use the OData.

                 

                It looks like from the above you are wanting the invokeHttp call to return json, but are still using xml processing on the json.  Do you need the Teiid procedure to return xml or json, and do you want the invokeHttp call to return xml or json?

                • 5. Re: how the Rest War can return json
                  tejones

                  Hi Levi,

                   

                  You can use the Teiid Designer generated REST war to do this which exposes both XML and JSON operations. Have look at Teiid Designer User Guide.

                   

                  Thanks,

                  Ted

                  • 6. Re: how the Rest War can return json
                    lv_levi

                    hi Ted,

                         I add the json beween Modle and get of my visit url,it's returns the json fomart info. thanks you Ted.

                     

                    Thanks,

                    Levi

                    1 of 1 people found this helpful
                    • 7. Re: how the Rest War can return json
                      lv_levi

                      hi Steven,

                           I add the json to the vistit url fllows the TD user Guide which can resolve my problems. thanks for your response!

                       

                       

                       

                      thanks,

                      Levi