Skip to content

Instantly share code, notes, and snippets.

@FroMage
Created June 18, 2019 08:51
Show Gist options
  • Save FroMage/bfd2da921d797e9e1bb25f7d8c4ccf7e to your computer and use it in GitHub Desktop.
Save FroMage/bfd2da921d797e9e1bb25f7d8c4ccf7e to your computer and use it in GitHub Desktop.
package com.test;
import java.util.List;
import io.quarkus.panache.json.JpaIntegration;
import io.quarkus.panache.json.NestledRelation;
import io.quarkus.panache.json.Relation;
import io.quarkus.panache.json.Rename;
import io.quarkus.panache.json.SerializedView;
import io.quarkus.panache.json.ViewDescription;
public class EntityView2 extends SerializedView<Entity> {
// remove a field
@Remove
public String removeMe;
// rename a field, change its JPA mapping and its view mapping
@JpaIntegration(JpaIntegration.READ_WRITE)
@Rename("renameMe")
public List<EntityView2> betterName;
// specify the serialised fields
@Include({"id", "keepMe"})
public List<Entity> relation;
// change a view mapping and its JPA mapping
@JpaIntegration(JpaIntegration.NONE)
public EntityView2.OtherRelationView otherRelation;
// add a new property
public int newProperty;
//this is some extra data that we want to include in the GET request to reduce the number of HTTP
//requests needed to load the page
private List<Entity2> selectionBoxList;
// required constructor
public EntityView2(Entity entity) {
super(entity);
// only new properties need to be initialised
newProperty = entity.keepMe + 2;
this.selectionBoxList = selectionBoxList;
}
// new dynamic property
public String getNewProperty2() {
return "foo";
}
// change a field mapping to only include the ID
public int getIdOnlyRelation(){
return get().idOnlyRelation.id;
}
@ReadOnly
public List<Entity2> getSelectionBoxList() {
return selectionBoxList;
}
public EntityView2 setSelectionBoxList(List<Entity2> selectionBoxList) {
this.selectionBoxList = selectionBoxList;
return this;
}
@ViewDescription
public class OtherRelationView extends SerializedView<Entity2> {
public OtherRelationView(Entity2 value) {
super(value);
}
public String getLabel() {
return "LABEL: " + get().name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment