从webservice下面成功调用,虽然省略了JSON名称包含下划线的字段...显示为null。
ShopifyProduct shopifyProducts = target.path( "admin" ).path( "products").queryParam("view","json").request( MediaType.APPLICATION_JSON_TYPE )
.header(HttpHeaders.AUTHORIZATION, basic ).accept( "application/json" )
.get( new GenericType<ShopifyProduct>(){});
顺便说一句,如果我重命名POJO字段
,我能够检索到正确的数据@JsonProperty("body_html")
private String body_html;
我尝试了几个POJO配置失败:
响应
{
"id": 9785936647,
"title": "Product1",
"body_html" : "<strong> description</strong>",
"variants": [
{
"id": 37797111879,
"product_id": 9785936647,
"title": "Default Title",
}
]
}
POJO
@JsonIgnoreProperties( ignoreUnknown=true )
@JsonInclude( JsonInclude.Include.NON_EMPTY )
public class ShopifyProduct implements Serializable {
private static final long serialVersionUID = 1L;
public ShopifyProduct() {
// TODO Auto-generated constructor stub
}
@JsonProperty( "id" )
private Long id;
@JsonProperty( "title" )
private String title;
@JsonProperty( "body_html" )
private String bodyHtml;
....
....
//Getters and Setters
}
结果
{
"id": 9785936647,
"title": "Product1",
"body_html" : null,
"variants": [
{
"id": 37797111879,
"product_id": null,
"title": "Default Title",
}
]
}