de.ingogriebsch.spring.hateoas.siren.Jackson2SirenModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-hateoas-siren Show documentation
Show all versions of spring-hateoas-siren Show documentation
A library implementing Siren as a custom Spring HATEOAS hypermedia type. Siren is a hypermedia specification for representing entities.
The newest version!
/*-
* Copyright 2019-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 de.ingogriebsch.spring.hateoas.siren;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.mediatype.hal.RepresentationModelMixin;
/**
* Jackson {@link Module} to serialize and deserialize all the parts of Siren entities.
*
* @author Ingo Griebsch
* @since 1.0.0
* @see Module
*/
class Jackson2SirenModule extends SimpleModule {
private static final Version MODULE_VERSION = new Version(1, 1, 0, null, "de.ingogriebsch.hateoas", "spring-hateoas-siren");
private static final long serialVersionUID = 7377778164657569053L;
Jackson2SirenModule() {
super("siren-module", MODULE_VERSION);
setMixInAnnotation(RepresentationModel.class, RepresentationModelMixIn.class);
setMixInAnnotation(EntityModel.class, EntityModelMixIn.class);
setMixInAnnotation(CollectionModel.class, CollectionModelMixIn.class);
setMixInAnnotation(PagedModel.class, PagedModelMixIn.class);
setMixInAnnotation(SirenModel.class, SirenModelMixIn.class);
setMixInAnnotation(SirenModel.EmbeddedRepresentation.class, SirenModelMixIn.EmbeddedRepresentationMixIn.class);
}
@JsonSerialize(using = SirenRepresentationModelSerializer.class)
@JsonDeserialize(using = SirenRepresentationModelDeserializer.class)
abstract static class RepresentationModelMixIn extends RepresentationModel {
}
@JsonSerialize(using = SirenEntityModelSerializer.class)
@JsonDeserialize(using = SirenEntityModelDeserializer.class)
abstract static class EntityModelMixIn extends EntityModel {
}
@JsonSerialize(using = SirenCollectionModelSerializer.class)
@JsonDeserialize(using = SirenCollectionModelDeserializer.class)
abstract static class CollectionModelMixIn extends CollectionModel {
}
@JsonSerialize(using = SirenPagedModelSerializer.class)
@JsonDeserialize(using = SirenPagedModelDeserializer.class)
abstract static class PagedModelMixIn extends PagedModel {
}
@JsonSerialize(using = SirenModelSerializer.class)
abstract static class SirenModelMixIn extends SirenModel {
@JsonSerialize(using = SirenModelSerializer.EmbeddedRepresentationSerializer.class)
abstract static class EmbeddedRepresentationMixIn extends SirenModel.EmbeddedRepresentation {
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy