杰克逊没有解析下划线领域

时间:2017-03-16 14:58:06

标签: java json jackson

从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配置失败:

  1. 删除@JsonProperty并离开@JsonNaming
  2. 删除@JsonNaming并离开@JsonProperty
  3. 杰克逊2.8.7

    响应

    {
         "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",
            }
         ]
      }
    

0 个答案:

没有答案