Encodes entity or id as JSON. If isNull returns null.
null
Object? entityOrIdToJson() { if (isNull) return null; if (isEntitySet) { return entityToJson(); } else if (isIdSet) { return id!; } else { return null; } }