Java 杰克逊没有';不解析下划线字段
虽然省略了JSON名称包含下划线的字段,但从webservice下面调用成功…显示为nullJava 杰克逊没有';不解析下划线字段,java,json,jackson,Java,Json,Jackson,虽然省略了JSON名称包含下划线的字段,但从webservice下面调用成功…显示为null ShopifyProduct shopifyProducts = target.path( "admin" ).path( "products").queryParam("view","json").request( MediaType.APPLICATION_JSON_TYPE ) .header(HttpHeaders.AUTHORIZATIO
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配置,但均未成功:
{
"id": 9785936647,
"title": "Product1",
"body_html" : "<strong> description</strong>",
"variants": [
{
"id": 37797111879,
"product_id": 9785936647,
"title": "Default Title",
}
]
}
结果
{
"id": 9785936647,
"title": "Product1",
"body_html" : null,
"variants": [
{
"id": 37797111879,
"product_id": null,
"title": "Default Title",
}
]
}
只要您通过
@JsonProperty
提供名称,就不需要使用@JsonNaming
。你能提供一个答案吗?实际的问题是什么,你能重新表述一下吗?这样我们就能更好地理解它了吗?这有帮助吗?我已经编辑了回复和最终结果。Jackson、Jersey和so没有额外的配置。@alain.janinm不幸的是没有,因为Jackson 2.7代表SnakeCaseStrategy不推荐该策略,我尝试了但没有成功。
@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",
}
]
}