// related one
if(IEntity.class.isAssignableFrom(ptype)) {
final RelationInfo ri = schemaInfo.getRelationInfo(entityClass, pname);
final boolean reference = ri.isReference();
if(shouldMarshalRelation(reference, depth, options)) {
final IEntity e = (IEntity) obj;
final Model m = e == null ? null : marshalEntity(e, options, visited, depth + 1);
final IEntityType etype =
ri.getRelatedType() == null ? null : etResolver.resolveEntityType(e == null ? ri.getRelatedType() : e
.entityClass());
prop = new RelatedOneProperty(etype, m, pname, reference);
}
}
// related many collection
else if(Collection.class.isAssignableFrom(ptype)) {
final RelationInfo ri = schemaInfo.getRelationInfo(entityClass, pname);
final boolean reference = ri.isReference();
if(shouldMarshalRelation(reference, depth, options)) {
List<Model> list = null;
if(obj != null) {
list = new ArrayList<Model>();
final Collection<IEntity> set = (Collection<IEntity>) obj;
for(final IEntity e : set) {
final Model nested = marshalEntity(e, options, visited, depth + 1);
list.add(nested);
}
}
prop = new RelatedManyProperty(etResolver.resolveEntityType(ri.getRelatedType()), pname, reference, list);
}
}
// map (assume <String, String> type)
else if(Map.class.isAssignableFrom(ptype)) {
prop = new StringMapPropertyValue(pname, generatePropertyData(entityClass, pname), (Map) obj);
}
else {
final ISchemaProperty sp = schemaInfo.getSchemaProperty(entityClass, pname);
// nested property?
if(sp != null && sp.getPropertyType().isNested()) {
final BeanWrapperImpl bw2 = obj == null ? new BeanWrapperImpl(ptype) : new BeanWrapperImpl(obj);
for(final PropertyDescriptor pd2 : bw2.getPropertyDescriptors()) {
if(bw2.isWritableProperty(pd2.getName()) && isMarshalableProperty(pd2)) {
try {
final Object oval = bw2.getPropertyValue(pd2.getName());
model.set(createValueProperty(pd2.getPropertyType(), (pname + "_" + pd2.getName()), oval,
generatePropertyData(source.entityClass(), (pname + "." + pd2.getName()))));
}
catch(final RuntimeException e) {
log.debug("Didn't set nested model prop: " + pname + " due to: " + e.getMessage());
}
}
}
}