aacerox / node-rest-client

REST API client from node.js
MIT License
377 stars 132 forks source link

Updated node-rest-client from 1.8.0 to 3.0.0 but xml response to Json is not working properly. #143

Closed B-PRAVEEN closed 7 years ago

B-PRAVEEN commented 7 years ago

In old version 1.8.0, I simply pass header in each request and the xml response is parsed to Josn object, but now it is no working properly.

headers: {"Content-Type": "application/json"},

I tried this code :

var options = {
                mimetypes: {
                        json: ["application/json", "application/json;charset=utf-8"]

                    }
                };

var client = new Client(options);

But the output is like this:

{
  "ShipmentData": {
    "Shipment": [
      {
        "$": {
          "WaybillNo": "123123",
          "RefNo": "213213"
        },
        "Prodcode": [
          "A"
        ],
        "Service": [
          "Dart Apex - Door To Door"
        ],
        "PickUpDate": [
          "30 January 2017"
        ],
        "PickUpTime": [
          "2119"
        ],
        "Origin": [
          "123123"
        ],
        "OriginAreaCode": [
          "213"
        ],
        "Destination": [
          "12312"
        ],
        "DestinationAreaCode": [
          "VIJ"
        ],
        "ProductType": [
          "Non Documents"
        ],
        "CustomerCode": [
          "123123"
        ],
        "CustomerName": [
          "123123"
        ],
        "SenderName": [
          "123123"
        ],
        "ToAttention": [
          "Sai naidu"
        ],
        "Consignee": [
          "123123"
        ],
        "ConsigneeAddress1": [
          "123123"
        ],
        "ConsigneeAddress2": [
          "ada 123123 123123"
        ],
        "ConsigneePincode": [
          "12313"
        ],
        "ConsigneeTelNo": [
          "123213"
        ],
        "Weight": [
          "0.5"
        ],
        "Status": [
          "RETURNED TO ORIGIN AT SHIPPER'S REQUEST"
        ],
        "StatusType": [
          "RT"
        ],
        "ExpectedDeliveryDate": [
          "02 February 2017"
        ],
        "StatusDate": [
          "10 February 2017"
        ],
        "StatusTime": [
          "17:54"
        ],
        "Instructions": [
          "213123"
        ],
        "NewWaybillNo": [
          "123123"
        ],
        "Scans": [
          {
            "ScanDetail": [
              {
                "Scan": [
                  "RETURNED TO ORIGIN AT SHIPPER'S REQUEST"
                ],
                "ScanCode": [
                  "074"
                ],
                "ScanType": [
                  "RT"
                ],
                "ScanGroupType": [
                  "T"
                ],
                "ScanDate": [
                  "10-Feb-2017"
                ],
                "ScanTime": [
                  "17:54"
                ],
                "ScannedLocation": [
                  "213123"
                ],
                "ScannedLocationCode": [
                  "123123"
                ]
              },

Every element is array, any solution?

In V1.8.0 Json parser work correctly.

aacerox commented 7 years ago

hi it's an "issue" in xml2js lib. Since version 0.2 every value inside a tag is returned as an array (explicitArray option). But fortunately you can disable that mode.

I'm going to create new version 3.0.1 with that mode disabled to maintain backward compatibility.

thnx

aacerox commented 7 years ago

fixed in version 3.0.1.