I am trying to take some JSON that looks like this (from AlphaVantage):
{
"Symbol": "IBM",
"AssetType": "Common Stock",
"Name": "International Business Machines Corporation",
... more properties
}
And parse it using Jackson (& Ebeans):
ObjectMapper objectMapper = new ObjectMapper();
String json = response.body().string();
Stock stock = objectMapper.readValue(json, Stock.class);
stock.save();
My Stock class looks like this:
@Entity
@Table(name = "stock")
public class Stock extends Model {
@Id
private Long id;
private String Symbol;
private String AssetType;
private String Name;
... other properties
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getSymbol() {
return this.Symbol;
}
public void setSymbol(String Symbol) {
this.Symbol = Symbol;
}
... other setters/getters
}
Instead I am getting the following error:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Symbol" (class com.myprojectname.Stock), not marked as ignorable (60 known properties: "ebitda", "sharesOutstanding", "bookValue", ....more fields
Why is Jackson having a problem connecting to my Stock class? How do I connect Symbol from the JSON into Symbol in the Stock class?
EDIT: I get the same error message if I change symbol to lowercase:
@Entity
@Table(name = "stock")
public class Stock extends Model {
@Id
private Long id;
private String symbol;
public String getSymbol() {
return this.symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
}