Skip to content

Commit

Permalink
[spring-projects#1300] Fix jackson serialization test
Browse files Browse the repository at this point in the history
  • Loading branch information
Patouche committed Jun 3, 2020
1 parent fd132c9 commit c786d97
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.hateoas.mediatype;

import org.springframework.hateoas.AbstractCollectionModel;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;

Expand Down Expand Up @@ -49,7 +50,7 @@ public static JavaType findRootType(JavaType contentType) {
public static boolean isResourcesOfResource(JavaType type) {

return
CollectionModel.class.isAssignableFrom(type.getRawClass())
AbstractCollectionModel.class.isAssignableFrom(type.getRawClass())
&&
EntityModel.class.isAssignableFrom(type.containedType(0).getRawClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ static class CollectionJsonPagedResourcesSerializer extends ContainerSerializer<
}

CollectionJsonPagedResourcesSerializer(@Nullable BeanProperty property) {

super(CollectionModel.class, false);
super(PagedModel.class, false);
this.property = property;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
* Custom mixin to to render collection content as {@literal _embedded}.
* Custom mixin to render collection content as {@literal _embedded}.
*
* @author Alexander Baetz
* @author Oliver Gierke
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.Links;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.mediatype.MessageResolver;
import org.springframework.hateoas.mediatype.hal.HalConfiguration.RenderSingleLinks;
Expand Down Expand Up @@ -91,6 +92,7 @@ public Jackson2HalModule() {
setMixInAnnotation(Link.class, LinkMixin.class);
setMixInAnnotation(RepresentationModel.class, RepresentationModelMixin.class);
setMixInAnnotation(CollectionModel.class, CollectionModelMixin.class);
setMixInAnnotation(PagedModel.class, PagedModelMixin.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.hateoas.mediatype.hal;

import java.util.Collection;

import org.springframework.hateoas.PagedModel;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;


/**
* Custom mixin to render collection content under {@literal _embedded} element.
*
* @author Patrick ALLAIN
*/
@JsonPropertyOrder({ "content", "links" })
abstract class PagedModelMixin<T> extends PagedModel<T> {

@Override
@JsonProperty("_embedded")
@JsonInclude(Include.NON_EMPTY)
@JsonSerialize(using = Jackson2HalModule.HalResourcesSerializer.class)
@JsonDeserialize(using = Jackson2HalModule.HalResourcesDeserializer.class)
public abstract Collection<T> getContent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ abstract class CollectionModelMixin<T> extends CollectionModel<T> {
public abstract Collection<T> getContent();
}

@JsonSerialize(using = HalFormsCollectionModelSerializer.class)
abstract class PagedModelMixin<T> extends PagedModel<T> {

@Override
@JsonProperty("_embedded")
@JsonInclude(Include.NON_EMPTY)
@JsonDeserialize(using = HalFormsCollectionModelDeserializer.class)
public abstract Collection<T> getContent();

@Nullable
@Override
@JsonProperty("page")
Expand Down

0 comments on commit c786d97

Please sign in to comment.