1

I need to use a response from a rest service returning JSON. However, one of the fields in the json response is the empty string. So, basically this:

{"wut":
  {
   "foo":"fooval", 
   "": "srsly"
  }
}

So, I need to somehow translate this into a java class, as below:

@JsonIgnoreProperties(ignoreUnknown=true)
public class wut
{
    @JsonProperty
    private String foo;

    @JsonProperty
    private String <empty string???>;

    //etc...
}

As you might expect, I don't have enough control over the endpoint to be able to give the property a name. Is there a way to handle this?

I'm using RestTemplate from spring to make the call, if that matters at all.

Kel
  • 111
  • 1
  • 1
  • 7
  • Have you ever seen a JSON object with an empty property name!! How the schema of your JSON object looks like? – Kh.Taheri Feb 02 '17 at 18:34
  • 1
    @Kh.Taheri Obviously they have seen it... that's why this question exists. You could try a custom deserializer using the `@JsonDeserializer` annotation and extending `JsonDeserializer`. – Christopher Schneider Feb 02 '17 at 18:44
  • @ChristopherSchneider, thank you; I got it .. Therefore, I think this link http://stackoverflow.com/questions/11376304/right-way-to-write-json-deserializer-in-spring-or-extend-it would be helpful to him. – Kh.Taheri Feb 02 '17 at 18:48
  • Actually, there is no possible way to deserialize json with empty key to java object. The reason is that object field should has name defined according to java specification. Empty string is not allowed. – eg04lt3r Feb 02 '17 at 19:32

0 Answers0