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,508
  • 21
  • 34

2 Answers2

1

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

@JsonProperty("error-codes")
private List<ErrorCodes> errorCodes;
cassiomolin
  • 113,708
  • 29
  • 249
  • 319
1

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,311
  • 3
  • 25
  • 30