0

I'm trying to deserialize a json with the following structure

{
    header: {
         type: "esummary",
         version: "0.3"
    },
    result: {
         22807455: {
              uid: "22807455",
              pubdate: "2012 Jul",
              epubdate: "",
         },
    uids: [
          "22807455"
    ]
  }
}

My main class PubmedResponse and the subclass PubmedResultMap is:

@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class PubmedResponse {

    @JsonProperty("header")
    PubmedHeader header;

    @JsonProperty("result")
    PubmedResultMap resultMap;

}

@Getter
@Setter
@JsonIgnoreProperties
public class PubmedResultMap implements PubmedInfo{

    Map<String, PubmedResult> results;

    @JsonProperty("uids")
    List<String> uids;
}

However, the PubmedResultMap can't deserialize the Map starting with 22807455 and in the json I don't have a property to map to my attribute in that class. Does anyone faced that problem before.? This is the full json https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=22807455&retmode=json

ypriverol
  • 585
  • 2
  • 8
  • 28
  • json key is `result` your object property is `results`? – deadshot Jun 08 '22 at 15:13
  • The json specification only allows string keys. I don't know how this was generated, but it's not a valid json. – Chaosfire Jun 08 '22 at 15:14
  • well, `22807455` is an unknown key so it is correct that it does not get picked up. Moreover there is no `results` in `result` so how do you expect Map in PubmedResultMap to be populated – Antoniossss Jun 08 '22 at 15:14
  • Possible duplicate - [Using number as "index" (JSON)](https://stackoverflow.com/questions/8758715/using-number-as-index-json). – Chaosfire Jun 08 '22 at 15:17
  • Thanks, @Chaosfire the json is generated but another service and that is what I want to parse. I will not generate in that way, but is an external service. – ypriverol Jun 08 '22 at 18:42
  • @Antoniossss How can can declare that map that do not have property name.? – ypriverol Jun 08 '22 at 18:42
  • Literally as map. "result" is map right away, nothing to wrap – Antoniossss Jun 09 '22 at 06:49

0 Answers0