[MarkLogic Dev General] rest services return xml instead of json

Vinayagam, Jothiprakash (Conduent) Jothiprakash.Vinayagam at conduent.com
Thu Feb 2 08:39:04 PST 2017


Dev: 8.0-5.8
Local: 8.0-6

From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Keith Breinholt
Sent: Thursday, February 02, 2017 11:16 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] rest services return xml instead of json

What versions of MarkLogic are your local and dev databases running?

-Keith

From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Vinayagam, Jothiprakash (Conduent)
Sent: Thursday, February 02, 2017 8:02 AM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] rest services return xml instead of json

I got it. Strange thing here  if I point to local database it returning json and if I point to dev database it returning xml. Its wired. Please advise

From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Geert Josten
Sent: Thursday, February 02, 2017 3:55 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] rest services return xml instead of json

Hi Jothi,

The outputTypes only influences the Content-type header(s), not causes output to get formatted automatically. I recommend making sure you really return a JSON object in your REST extension (e.g. object-node() or a true JavaScript JSON object), or convert your result to JSON string. You might wanna look into xdmp.toJSON, xdmp.toJsonString, json.transformToJson (you need to import the xqy module of json:transform-to-json for this), or if working with database nodes $mynode.toObject()..

Cheers,
Geert

From: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of "Vinayagam, Jothiprakash (Conduent)" <Jothiprakash.Vinayagam at conduent.com<mailto:Jothiprakash.Vinayagam at conduent.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Thursday, February 2, 2017 at 1:17 AM
To: "'general at developer.marklogic.com<mailto:'general at developer.marklogic.com>'" <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: [MarkLogic Dev General] rest services return xml instead of json

HI all,

We wrote rest service below to get the data. It returns as xml instead of json

<?xml version="1.0" encoding="UTF-8"?>
<json:array xmlns:json="http://marklogic.com/xdmp/json<https://urldefense.proofpoint.com/v2/url?u=http-3A__marklogic.com_xdmp_json&d=DwMFAg&c=z0adcvxXWKG6LAMN6dVEqQ&r=wQ09nIebnRJGH1VgSesPfFnvXo10BKdu-taGZQaoghw&m=6YfTNXqiBQCMGKx4NvaIdYqGMpushI7zY8WXEy9wiYk&s=rXl1EvhK0g2o29NJ7tqvC-UjZWw30qoktvKBw8dJYjg&e=>" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema-2Dinstance&d=DwMFAg&c=z0adcvxXWKG6LAMN6dVEqQ&r=wQ09nIebnRJGH1VgSesPfFnvXo10BKdu-taGZQaoghw&m=6YfTNXqiBQCMGKx4NvaIdYqGMpushI7zY8WXEy9wiYk&s=U0sad5WlcmimVjuTeef2yYqowoFmxuJwgHQh-v1We6w&e=>" xmlns:xs="http://www.w3.org/2001/XMLSchema<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema&d=DwMFAg&c=z0adcvxXWKG6LAMN6dVEqQ&r=wQ09nIebnRJGH1VgSesPfFnvXo10BKdu-taGZQaoghw&m=6YfTNXqiBQCMGKx4NvaIdYqGMpushI7zY8WXEy9wiYk&s=C7kO_uQcdpfA6hxbNgvLd4z8DIP3qx1Xn-PZLLjltw8&e=>">
  <json:value><json:object>
      <json:entry key="2017-01">
        <json:value><json:array>
            <json:value><json:object>
               <json:entry key="">
                 <json:value xsi:type="xs:integer">24309</json:value>
               </json:entry>
              </json:object></json:value>
</json:array>



function get(context, params) {
    context.outputTypes = [];
    context.outputTypes.push('application/json');


    var date = (typeof params.fromDate === 'undefined') ? null : params.fromDate;
    var endDate = (typeof params.toDate === 'undefined') ? null : params.toDate;
    var doNum = (typeof params.doNum === 'undefined') ? null : params.doNum;
    var ldssID = (typeof params.ldssID === 'undefined') ? null : params.ldssID;
    console.log("testing" + params.fromDate);
    console.log("testing" + params.toDate);


// some code


}



Rest service called from controller:

            MLRest.extension('abawdDashboard', {
                method: 'GET',
                params: { 'rs:fromDate': fromDateRunReport, 'rs:toDate': toDateRunReport, 'rs:doNum': $scope.dashboard.doID, 'rs:ldssID': $scope.dashboard.ldssID }
            }).then(function(response) {
                console.log("run report" + response.data);
                $scope.indexedObjects = response.data;
                $scope.dashBoardData = response.data;
                var curYear = new Date();
                populateCount(fromDateRunReport, toDateRunReport, response.data);
                //$rootScope.$emit('rootScope:emit', 'Emit!'); // $rootScope.$on
                //$rootScope.$broadcast('rootScope:broadcast', response.data);
                //$scope.indexedObjects = indexByAttribute(response.data);
            });


Note: same working fine in my local if I deploy dev/test it returning xml instead of json

Thanks
Jothi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20170202/1b440650/attachment.html 


More information about the General mailing list