【问题标题】:AWS Neptune HTTP REST change response serializer from GraphSON to JSONAWS Neptune HTTP REST 将响应序列化程序从 GraphSON 更改为 JSON
【发布时间】:2021-07-20 15:52:22
【问题描述】:

我正在使用这个 sample 从 Lambda 进行 HTTP REST 查询。

名为GraphSON的输出格式

{
  "requestId": "104803b-e5d-4e49-bad8-e95e32fe7f0",
  "status": {
    "message": "",
    "code": 200,
    "attributes": {
      "@type": "g:Map",
      "@value": []
    }
  },
  "result": {
    "data": {
      "@type": "g:List",
      "@value": []
    },
    "meta": {
      "@type": "g:Map",
      "@value": []
    }
  }
}

我的一般问题是如何指定 serializer 并在没有 g:Map@valueJSON 输出而不是 GraphSON /em> 等

我尝试过的:为Content-Type 设置特定值:

  • application/json
  • application/x-amz-json-1.1
  • application/vnd.gremlin-v3.0+json

我还尝试在GET 参数中使用上述值作为serializer 的参数,例如:

https://{host}:{port}/gremlin/?gremlin={query}&serializer=application/vnd.gremlin-v3.0+json

但是返回的数据格式还是GraphSON。

【问题讨论】:

    标签: gremlin amazon-neptune


    【解决方案1】:

    您可以回退到应该产生格式良好的 JSON 的 GraphSON V2。它仍然会有一些类型注释,但不包括映射类型。例如:

    host='https://your-host-name.neptune.amazonaws.com'
    curl -X POST $host:8182/gremlin\
         -d "{\"gremlin\":\"g.V('3').limit(1)\"}"\
         -H "Accept:application/vnd.gremlin-v2.0+json"\
         -H "Content-Type:application/vnd.gremlin-v2.0+json" | jq .
    

    产量

    {
      "requestId": "e053be96-73e7-4fc0-b02e-07bdf638cabc",
      "status": {
        "message": "",
        "code": 200,
        "attributes": {}
      },
      "result": {
        "data": [
          {
            "@type": "g:Vertex",
            "@value": {
              "id": "3",
              "label": "airport",
              "properties": {
                "country": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": 1352763338
                      },
                      "value": "US",
                      "label": "country"
                    }
                  }
                ],
                "longest": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": 134047490
                      },
                      "value": {
                        "@type": "g:Int32",
                        "@value": 12250
                      },
                      "label": "longest"
                    }
                  }
                ],
                "code": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": -1353043840
                      },
                      "value": "AUS",
                      "label": "code"
                    }
                  }
                ],
                "city": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": -342536989
                      },
                      "value": "Austin",
                      "label": "city"
                    }
                  }
                ],
                "elev": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": -1300513844
                      },
                      "value": {
                        "@type": "g:Int32",
                        "@value": 542
                      },
                      "label": "elev"
                    }
                  }
                ],
                "icao": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": -1123166874
                      },
                      "value": "KAUS",
                      "label": "icao"
                    }
                  }
                ],
                "lon": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": -1327799778
                      },
                      "value": {
                        "@type": "g:Double",
                        "@value": -97.6698989868164
                      },
                      "label": "lon"
                    }
                  }
                ],
                "runways": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": 200353151
                      },
                      "value": {
                        "@type": "g:Int32",
                        "@value": 2
                      },
                      "label": "runways"
                    }
                  }
                ],
                "region": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": 1821242579
                      },
                      "value": "US-TX",
                      "label": "region"
                    }
                  }
                ],
                "type": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": -1535682079
                      },
                      "value": "airport",
                      "label": "type"
                    }
                  }
                ],
                "lat": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": -23584191
                      },
                      "value": {
                        "@type": "g:Double",
                        "@value": 30.1944999694824
                      },
                      "label": "lat"
                    }
                  }
                ],
                "desc": [
                  {
                    "@type": "g:VertexProperty",
                    "@value": {
                      "id": {
                        "@type": "g:Int32",
                        "@value": -2074163175
                      },
                      "value": "Austin Bergstrom International Airport",
                      "label": "desc"
                    }
                  }
                ]
              }
            }
          }
        ],
        "meta": {}
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 2019-10-28
      • 1970-01-01
      相关资源
      最近更新 更多