简体   繁体   中英

How to ignore dynamic key when deserialising JSON with jackson

I am trying to access the data inside the X-Amz-Content-Sha256 parameter, but the X-Amz-Content-Sha256 key is different for each request so I cannot hardcode the key value.

Is there a way to access an object without knowing its key, when using mapper.readValue()?

"components": {
    "parameters": {
      "X-Amz-Content-Sha256": {
        "name": "X-Amz-Content-Sha256",
        "in": "header",
        "schema": {
          "type": "string"
        },
      }
    }
}

You need to deserialize it to Map . Then you can check Map key to get desired values.

Sample code to deserialize JSON string to Map:

ObjectReader reader = new ObjectMapper().readerFor(Map.class);

Map<String, Object> jsonMap = reader.readValue(jsonString);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM