*/
public abstract X fromJson(EntityManager em, JSONValue jsonValue);
public JSONValue toJson(EntityManager em, X sourceEntity) {
final ErraiEntityManager eem = (ErraiEntityManager) em;
JSONObject jsonValue = new JSONObject();
for (Attribute<? super X, ?> a : getAttributes()) {
ErraiAttribute<? super X, ?> attr = (ErraiAttribute<? super X, ?>) a;
switch (attr.getPersistentAttributeType()) {
case ELEMENT_COLLECTION:
case EMBEDDED:
case BASIC:
jsonValue.put(attr.getName(), makeInlineJson(sourceEntity, attr, eem));
break;
case MANY_TO_MANY:
case MANY_TO_ONE:
case ONE_TO_MANY:
case ONE_TO_ONE:
JSONValue attributeValue;
if (attr instanceof ErraiSingularAttribute) {
attributeValue = makeJsonReference(sourceEntity, (ErraiSingularAttribute<? super X, ?>) attr, eem);
}
else if (attr instanceof ErraiPluralAttribute) {
attributeValue = makeJsonReference(sourceEntity, (ErraiPluralAttribute<? super X, ?, ?>) attr, eem);
}
else {
throw new PersistenceException("Unknown attribute type " + attr);
}
jsonValue.put(attr.getName(), attributeValue);
}
}
return jsonValue;
}