Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 杰克逊没有';不解析下划线字段_Java_Json_Jackson - Fatal编程技术网

Java 杰克逊没有';不解析下划线字段

Java 杰克逊没有';不解析下划线字段,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

虽然省略了JSON名称包含下划线的字段,但从webservice下面调用成功…显示为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并保留@JsonNaming
  • 删除@JsonNaming并保留@JsonProperty
  • 杰克逊2.8.7

    回应

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