首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将响应序列化程序从GraphSON更改为JSON

将响应序列化程序从GraphSON更改为JSON
EN

Stack Overflow用户
提问于 2021-07-20 15:52:22
回答 1查看 143关注 0票数 0

我使用这个示例从Lambda进行HTTP查询。

名为GraphSON的输出格式

代码语言:javascript
复制
{
  "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": []
    }
  }
}

我的一般问题是如何指定序列化程序并获得格式良好的JSON输出,而不是没有g:Map、@value等的GraphSON

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

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

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

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

但是返回的数据格式仍然是GraphSON。

EN

回答 1

Stack Overflow用户

发布于 2021-07-21 22:22:00

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

代码语言:javascript
复制
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 .

产额

代码语言:javascript
复制
{
  "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": {}
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68457882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档