
br.eti.clairton.vraptor.crud.serializer.AbstractModelSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vraptor-crud Show documentation
Show all versions of vraptor-crud Show documentation
A crud bootstrap do use VRaptor
The newest version!
package br.eti.clairton.vraptor.crud.serializer;
import static br.eti.clairton.inflector.Inflector.getForLocale;
import static br.eti.clairton.inflector.Locale.pt_BR;
import static javax.enterprise.inject.spi.CDI.current;
import java.lang.annotation.Annotation;
import java.util.Collection;
import javax.persistence.EntityManager;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonSerializer;
import br.eti.clairton.inflector.Inflector;
import br.eti.clairton.jpa.serializer.GsonJpaSerializer;
import br.eti.clairton.jpa.serializer.Nodes;
import br.eti.clairton.jpa.serializer.NodesProgramatic;
import br.eti.clairton.model.Model;
import br.eti.clairton.security.Resource;
public abstract class AbstractModelSerializer extends GsonJpaSerializer implements JsonSerializer, JsonDeserializer, Resourceable {
private static final long serialVersionUID = 1L;
private final br.eti.clairton.jpa.serializer.Tagable tagable;
public AbstractModelSerializer(final Inflector inflector, final EntityManager em) {
this(new NodesProgramatic(), inflector, em);
}
public AbstractModelSerializer(final Nodes nodes, final Inflector inflector, final EntityManager em) {
super(nodes, em);
this.tagable = new Tagable(inflector){
private static final long serialVersionUID = 1L;
@Override
public String getRootTag(final T src) {
return AbstractModelSerializer.this.getRootTag(src);
}
@Override
public String getResource(final T src) {
return AbstractModelSerializer.this.getResource(src);
}
@Override
public String getResource(final Collection src) {
return AbstractModelSerializer.this.getResource(src);
}
};
}
public AbstractModelSerializer() {
this(getForLocale(pt_BR), null);
}
@Override
public String getRootTagCollection(final Collection collection) {
return tagable.getRootTagCollection(collection);
}
@Override
public String getResource(final T src) {
return current().select(String.class, RQ).get();
}
@Override
public String getResource(final Collection src) {
return current().select(String.class, RQ).get();
}
private static final Resource RQ = new Resource() {
@Override
public Class extends Annotation> annotationType() {
return Resource.class;
}
@Override
public String value() {
return "";
}
};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy