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: 
<[email protected]<mailto:[email protected]>>
 on behalf of "Vinayagam, Jothiprakash (Conduent)" 
<[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Thursday, February 2, 2017 at 1:17 AM
To: 
"'[email protected]<mailto:'[email protected]>'" 
<[email protected]<mailto:[email protected]>>
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"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xs="http://www.w3.org/2001/XMLSchema";>
  <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
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to