2016-08-26 3 views
3

私は春のデータ休憩でAPIを作成する過程にあり、レスポンスで生成されたフィールドをちょっと混乱させ、それらのいくつかを取り除く方法があるかどうか疑問に思っていました。私はAPPLICATION_JSONにメディアタイプを設定しており、多くの項目の応答は、次の3つのフィールドがあります。春のデータレスト - コンテンツフィールド?

  1. リンク(など最初のページへのリンクのための配列、次のページ、最後のページ、)
  2. コンテンツ(データの配列)
  3. ページ(ページ上の情報)

私は、これらのフィールドのすべてをしたいが、しかし、コンテンツの配列内の各オブジェクトは、完全に不必要であるコンテンツやリンクのフィールドがあります。リンクはそれ自身を指しており、コンテンツは常に空です。ここで返される項目の例です:

{ 
    "id" : 9, 
    "positionNumber" : "F38520", 
    "openDate" : "2014-11-11T05:00:00.000+0000", 
    "description" : "Research: This position is responsible for research related activities including, but not limited to, research design and implementation, preparation of grant proposals to both intramural and extramural funding sources, both collaborating on and leading manuscript development for submissions to peer-review journals.", 
    "type" : { 
    "title" : "Teaching and Research Faculty", 
    "code" : null 
    }, 
    "category" : null, 
    "recruitmentType" : { 
    "name" : "Public" 
    } }, 
    "content" : [ ], 
    "links" : [ { 
    "rel" : "self", 
    "href" : "https://localhost/v1/items/9" 
    }, { 
    "rel" : "item", 
    "href" : "https://localhost/v1/items/9" 
    } ] 
} 

また、メディアタイプがAPPLICATION_JSONなければならないので、私はちょうどHAL + JSONを使用するように設定することはできません。私はどこにでもこれに対する答えを探しました。それを理解しているようには見えない。助けをあらかじめありがとう!

+0

あなたは応答から[]コンテンツを除外する方法を見つけることがありますか? –

答えて

-1

このジャーを使用する必要がありますjackson-annotations-2.2.3.jarとあなたのDTOにアノテーションを適用して、例えばjsonを作っています。

@JsonInclude(JsonInclude.Include.NON_NULL) // this will not include null members of class in json 
    @JsonInclude(JsonInclude.Include.NON_EMPTY) // this will not include empty members of class in json 

これらは、クラスレベルとクラスメンバーレベルで適用できます。

たとえば、

@JsonInclude(JsonInclude.Include.NON_NULL) 
public class myDto { 

@JsonInclude(JsonInclude.Include.NON_EMPTY) 
public Content[] content; 

}

+0

それは春データRESTなので、DTOはありません –

+0

レスポンスありがとうございますが、私のクラスには実際には "コンテンツ"や "リンク"はありません。これらのフィールドは春 – Andrew

関連する問題