在导游中使用属性 Format=object 时无效 JSON

Invalid JSON when attributesFormat=object is used in the tourguide

我们在测试导游应用程序时发现 attributesFormat=object 存在问题 https://github.com/Fiware/tutorials.TourGuide-App

如果我们执行以下请求:

curl  <cb_host>:<cb_port>/v1/contextEntities/type/Restaurant/id/Elizalde -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' --header 'Accept: application/json'

我们得到这个有效的 JSON:

{
  "contextElement" : {
    "type" : "Restaurant",
    "isPattern" : "false",
    "id" : "Elizalde",
    "attributes" : [
      {
        "name" : "address",
        "type" : "",
        "value" : {
          "type" : "postalAddress",
          "streetAddress" : "Cuesta de las Cabras Aldapa 2",
          "addressRegion" : "Araba",
          "addressLocality" : "Alegría-Dulantzi",
          "postalCode" : "01240"
        }
      },
      {
        "name" : "aggregateRating",
        "type" : "",
        "value" : {
          "reviewCount" : 1,
          "ratingValue" : 3
        }
      },
      {
        "name" : "capacity",
        "type" : "PropertyValue",
        "value" : 120,
        "metadatas" : [
          {
            "name" : "name",
            "type" : "",
            "value" : "capacity"
          }
        ]
      },
      {
        "name" : "department",
        "type" : "",
        "value" : "Franchise3"
      },
      {
        "name" : "description",
        "type" : "",
        "value" : "Restaurante de estilo sidrería ubicado en Alegria-Dulantzi. Además de su menú del día y carta, también ofrece menú de sidrería. El menú del día cuesta 9 euros. Los fines de semana la especialidad de la casa son las alubias con sacramentos. En lo que a bebidas se refiere, hay una amplia selección además de la sidra. Cabe destacar que se puede hacer txotx. La capacidad del establecimiento es de 50 personas pero la sidrería no dispone de aparcamiento.%5cn%5cnHORARIO: %5cn%5cnLunes a domingo: 9:00-17:00 y 19:00-23:00."
      },
      {
        "name" : "occupancyLevels",
        "type" : "PropertyValue",
        "value" : 0,
        "metadatas" : [
          {
            "name" : "timestamp",
            "type" : "",
            "value" : ""
          },
          {
            "name" : "name",
            "type" : "",
            "value" : "occupancyLevels"
          }
        ]
      },
      {
        "name" : "position",
        "type" : "coords",
        "value" : "42.8404625, -2.5123277",
        "metadatas" : [
          {
            "name" : "location",
            "type" : "string",
            "value" : "WGS84"
          }
        ]
      },
      {
        "name" : "priceRange",
        "type" : "",
        "value" : 0
      },
      {
        "name" : "telephone",
        "type" : "",
        "value" : "945 400 868"
      }
    ]
  },
  "statusCode" : {
    "code" : "200",
    "reasonPhrase" : "OK"
  }
}

但是如果我们使用 attributesFormat=object:

curl  <cb_host>:<cb_port>/v1/contextEntities/type/Restaurant/id/Elizalde?attributesFormat=object -s -S --header 'Content-Type: application/json' --header 'x-auth-token:<token>' --header 'Fiware-service: tourguide' --header 'Accept: application/json'

我们得到这个无效的 JSON:

{
    "contextElement": {
        "type": "Restaurant",
        "isPattern": "false",
        "id": "Elizalde",
        "attributes": {
            "address": {
                "type": "",
                "value": {
                    "type": "postalAddress",
                    "streetAddress": "Cuesta de las Cabras Aldapa 2",
                    "addressRegion": "Araba",
                    "addressLocality": "Alegría-Dulantzi",
                    "postalCode": "01240"
                }
            },
            "aggregateRating": {
                "type": "",
                "value": {
                    "reviewCount": 1,
                    "ratingValue": 3
                }
            },
            "capacity": {
                "type": "PropertyValue",
                "120",
                "metadatas": [{
                    "name": "name",
                    "type": "",
                    "value": "capacity"
                }]
            },
            "department": {
                "type": "",
                "value": "Franchise3"
            },
            "description": {
                "type": "",
                "value": "Restaurante de estilo sidrería ubicado en Alegria-Dulantzi. Además de su menú del día y carta, también ofrece menú de sidrería. El menú del día cuesta 9 euros. Los fines de semana la especialidad de la casa son las alubias con sacramentos. En lo que a bebidas se refiere, hay una amplia selección además de la sidra. Cabe destacar que se puede hacer txotx. La capacidad del establecimiento es de 50 personas pero la sidrería no dispone de aparcamiento.%5cn%5cnHORARIO: %5cn%5cnLunes a domingo: 9:00-17:00 y 19:00-23:00."
            },
            "occupancyLevels": {
                "type": "PropertyValue",
                "0",
                "metadatas": [{
                    "name": "timestamp",
                    "type": "",
                    "value": ""
                }, {
                    "name": "name",
                    "type": "",
                    "value": "occupancyLevels"
                }]
            },
            "position": {
                "type": "coords",
                "value": "42.8404625, -2.5123277",
                "metadatas": [{
                    "name": "location",
                    "type": "string",
                    "value": "WGS84"
                }]
            },
            "priceRange": {
                "type": "",
                "0"
            },
            "telephone": {
                "type": "",
                "value": "945 400 868"
            }
        }
    },
    "statusCode": {
        "code": "200",
        "reasonPhrase": "OK"
    }
}

复制步骤:

猎户座版本信息:

<orion>
   <version>0.28.0</version>
    <uptime>0 d, 1 h, 12 m, 25 s</uptime>
    <git_hash>aaf8020a5de680b6d7e0c00c70cf425bcc4f39c8</git_hash>
    <compile_time>Mon Mar 21 13:20:37 UTC 2016</compile_time>
    <compiled_by>root</compiled_by>
    <compiled_in>838a42ae8431</compiled_in>
</orion>

这是由于 Orion 0.28.0 中 attributeFormat=object 渲染的错误。该错误将在 Orion 1.1.0 中修复,将于 2016 年 4 月底发布(它现在即将合并到 develop 分支,如果您想监控进度,请在the PR)。