0

when deserializing below JSON, it fails with above exception message when trying to parse the server attribute which has its type 'string' nested within it, how to parse a JSON which is having the attribute types nested within each attribute like below?

{
  "header": {
    "time": 1492178674232,
    "threadId": null,
    "requestMarker": null,
    "env": null,
    **"server": {
      "string": "astapp078"
    }**,
    "service": {
      "string": "ApiCalendarsEntityStreamPublisher"
    }
  }
}
Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
user2221654
  • 311
  • 1
  • 7
  • 20

1 Answers1

0

You can use the @JsonProperty annotation to specify a different name for the JSON field than the POJO field. And wrap the server and service fields in classes. E.g.

class POJO {
    Server server;
    Service service;
}

class Server {
    @JsonProperty("string") String name;
}

class Service {
    @JsonProperty("string") String name;
}

And name in server would be "astapp078"

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
  • i dont have access to the source files or any control how its serialized, as i am reading this message from a kafka topic. I only have the .class files as a dependency to parse these messages back to java object. – user2221654 Apr 26 '17 at 15:47