0

I am calling a rest service which returns a JSON Object and one the field is error-codes. Now how do I declare a variable in Java as '-' is not allowed.

The JSON is as follows

 {
      "success": true|false,
      "error-codes": [...]       
    }

This didn't worked

private List<ErrorCodes> errorCodes;

nor

private List<ErrorCodes> errorcodes; 
Abhishek Galoda
  • 2,753
  • 24
  • 38

2 Answers2

2

You must be using a JSON parser such as Jackson. In this case use:

@JsonProperty("error-codes")
private List<ErrorCodes> errorCodes;
cassiomolin
  • 124,154
  • 35
  • 280
  • 359
2

You didn't mention what kind of deserializer you use. Most deserializers work with some annotations on the fields. For example in Jackson, you could do:

@JsonProperty("error-codes")
private List<ErrorCodes> errorCodes;
Vlasec
  • 5,500
  • 3
  • 27
  • 30