
net.eusashead.parquet.http.serializer.hal.EntityRepresentationConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of parquet-web Show documentation
Show all versions of parquet-web Show documentation
Parquet is a Java REST framework built on Yoke and Vert.x
The newest version!
package net.eusashead.parquet.http.serializer.hal;
import java.util.Collection;
import net.eusashead.parquet.entity.Entity;
import net.eusashead.parquet.entity.Link;
import com.theoryinpractise.halbuilder.api.Representation;
import com.theoryinpractise.halbuilder.api.RepresentationFactory;
public class EntityRepresentationConverter implements
RepresentationConverter {
private final RepresentationFactory representationFactory;
public EntityRepresentationConverter(RepresentationFactory representationFactory) {
this.representationFactory = representationFactory;
}
@Override
public Representation convert(Entity source) {
// Create Representation
Representation representation = representationFactory.newRepresentation();
// Copy links
for (Link link : source.getLinks().values()) {
representation.withLink(link.rel(), link.href());
}
// Copy properties
for (String name : source.getProperties().keySet()) {
representation.withProperty(name, source.getProperty(name));
}
// Copy relations
for (String rel : source.getRelations().keySet()) {
Collection rels = source.getRelation(rel);
for (Entity entity : rels) {
Representation related = this.convert(entity);
representation.withRepresentation(rel, related);
}
}
// Return representation
return representation;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy