Merge pull request #121 from bsinno/fix_jsoncreator_pagedlist

fix json creator for PagedList for creating clients
This commit is contained in:
Kai Zimmermann
2016-04-05 13:17:31 +02:00

View File

@@ -14,9 +14,11 @@ import javax.validation.constraints.NotNull;
import org.springframework.hateoas.ResourceSupport; import org.springframework.hateoas.ResourceSupport;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* A list representation with meta data for pagination, e.g. containing the * A list representation with meta data for pagination, e.g. containing the
@@ -31,7 +33,9 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
public class PagedList<T> extends ResourceSupport { public class PagedList<T> extends ResourceSupport {
@JsonProperty
private final List<T> content; private final List<T> content;
@JsonProperty
private final long totalElements; private final long totalElements;
private final int size; private final int size;
@@ -41,14 +45,16 @@ public class PagedList<T> extends ResourceSupport {
* *
* @param content * @param content
* the actual content of the list * the actual content of the list
* @param total * @param totalElements
* the total amount of elements * the total amount of elements
* @throws NullPointerException * @throws NullPointerException
* in case {@code content} is {@code null}. * in case {@code content} is {@code null}.
*/ */
public PagedList(@NotNull final List<T> content, final long total) { @JsonCreator
public PagedList(@JsonProperty("content") @NotNull final List<T> content,
@JsonProperty("totalElements") final long totalElements) {
this.size = content.size(); this.size = content.size();
this.totalElements = total; this.totalElements = totalElements;
this.content = content; this.content = content;
} }