You aren’t following JavaBean standards, and without explicit instructions Jackson doesn’t know how to map your class.
The Java convention is to name properties like pplRow
, and your JSON is using the alternate Ruby style of ppl_row
. There are three options:
- Switch the entire Jackson engine to use an alternate style. (Not a great idea since it tends to cause collisions.
- Tell Jackson to use an alternate style for particular Java classes. (We’ll do this.)
- Annotate each property with
@JsonProperty
(works, but lots of extra effort).
Start by using standard Java naming for your properties:
class Profile14 {
private String pplRow;
public String getPplRow() {
return this.pplRow;
}
public void setPplRow(String s) {
this.pplRow = s;
}
}
Note that the naming of the methods is what defines the properties (since the backing field is private and technically doesn’t have to exist). Your existing properties both don’t match the names (pl
instead of ppl
) and don’t have the proper capitalization.
Now add this annotation to your class:
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
This tells Jackson to use snake_case
for naming all of the properties. This should be enough to get your mapping working.
CLICK HERE to find out more related problems solutions.