package mypackage.bean.hal; import mypackage.bean.ImmutableStyle; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.swagger.annotations.ApiModel; import java.util.List; import java.util.Map; import java.util.Optional; import org.immutables.value.Value; /** * The HateoasBean contains another Jackson-serializable bean plus links to other resources. * * It's done like this to not pollute all the JSON beans with _links entries. */ @ApiModel(value = "HALBean", description = "Root bean of all return values") @Value.Immutable @ImmutableStyle @JsonSerialize(as = ImmutableHalBean.class) @JsonDeserialize(as = ImmutableHalBean.class) public interface HalBean { @JsonUnwrapped Optional getBean(); @JsonProperty("_links") Optional getLinks(); @JsonProperty("_embedded") Map>> getEmbedded(); static HalBean of(final T bean, final Links links) { return ImmutableHalBean.builder().setBean(bean).setLinks(links).build(); } static HalBean of(final Links links) { return ImmutableHalBean.builder().setLinks(links).build(); } }