I create it in an editor gui at runtime dynamically. Each system has an editor gui (and an RMI service) which let me to add/edit/remove components provided by that system.
At first using a ModelPrefabEditor (and its RMI service ModelPrefabEditorClientService and ModelPrefabEditorHostedService) I create an entity with a ModelInfo, a SpawnPosition, an Interactable (this will make it clickable by mouse) and a Name component.
Then using PhysicEditor (and its RMI service PhysicEditorClientService and PhysicEditorHostedService) I can add/edit/remove physics components and collision shapes to it.
And in the similar way an StatEditor,… .
Beside that I can create/modify entity at runtime and see the result at the moment this is also user friendly to do it through a gui .
Finally after finished with editing I return to prefab editor and click on “Save As Prefab” and the result is gathered in a PrefabModel object
public class PrefabModel {
private List<EntityComponent> components;
private List<PrefabModel> children;
public PrefabModel() {
this.components = new ArrayList<>();
this.children = new ArrayList<>();
}
public PrefabModel(List<EntityComponent> components) {
this.components = components;
this.children = new ArrayList<>();
}
public <T extends EntityComponent> T getComponent(Class<T> classType) {
return (T) components.stream().filter(type -> classType.isInstance(type)).findFirst().get();
}
public List<EntityComponent> getComponents() {
return components;
}
public void setComponents(List<EntityComponent> components) {
this.components = components;
}
public List<PrefabModel> getChildren() {
return children;
}
public void setChildren(List<PrefabModel> children) {
this.children = children;
}
public EntityId clone(EntityData ed, EntityId parentId) {
EntityId clone = ed.createEntity();
components.forEach(component -> {
if (component instanceof Buff && !parentId.equals(EntityId.NULL_ID)) {
Buff buff = (Buff) component;
ed.setComponent(clone, new Buff(parentId, buff.getStartTime()));
return;
}
if (component instanceof ItemBuff && !parentId.equals(EntityId.NULL_ID)) {
ItemBuff buff = (ItemBuff) component;
ed.setComponent(clone, new ItemBuff(parentId, buff.getDecay()));
return;
}
ed.setComponent(clone, component);
});
children.forEach(child -> child.clone(ed, clone));
return clone;
}
}
I give it to Google’s Gson library and get a JSON string out of it. 
Yes, I am registering all prefab components at game server, and PrefabSystem uses it to retrieve component from entity when creating a PrefabModel.
protected void registerPrefaComponents(PrefabSystem prefabSystem) {
prefabSystem.register(ShapeInfo.class,
Mass.class,
Buff.class,
ItemBuff.class,
BoxShape.class,
SphereShape.class,
CylinderShape.class,
CapsuleShape.class,
Terrain.class,
TerrainBlock.class,
BridgeBlock.class,
BlockInfo.class,
BlockJoint.class,
ModelInfo.class,
Name.class,
SpawnPosition.class,
Interactable.class,
EntityTag.class,
Stat.class
);
}
Ah Yes, I can do this at editors hosted services, when I set the component on entity I can also add that component to the list (I mean not the component class name, but the component itself) in PrefabModel object. Do you mean this ?
Edit:
So when I click on that “Save As Prefab” button, I already have the PrefabModel object ready and I just need to serialize it to JSON with Gson.