throw new MarshallingException("no marshaller for type: " + toMap);
}
}
else {
if (context.canMarshal(type.getFullyQualifiedName())) {
Statement s = maybeAddAssumedTypes(tryBuilder, "c" + constructorParameters.size(),
mapping, fieldDemarshall(mapping, EJObject.class));
constructorParameters.add(s);
}
else {
throw new MarshallingException("no marshaller for type: " + type);
}
}
}
if (instantiationMapping instanceof ConstructorMapping) {
final ConstructorMapping mapping = (ConstructorMapping) instantiationMapping;
final MetaConstructor constructor = mapping.getMember();
if (constructor.isPublic()) {
tryBuilder.append(Stmt.declareVariable(toMap).named("entity")
.initializeWith(Stmt.newObject(toMap, constructorParameters.toArray(new Object[constructorParameters.size()]))));
}
else {
PrivateAccessUtil.addPrivateAccessStubs(gwtTarget ? "jsni" : "reflection", context.getClassStructureBuilder(), constructor);
tryBuilder.append(Stmt.declareVariable(toMap).named("entity")
.initializeWith(
Stmt.invokeStatic(
context.getClassStructureBuilder().getClassDefinition(),
PrivateAccessUtil.getPrivateMethodName(constructor),
constructorParameters.toArray(new Object[constructorParameters.size()]))));
}
}
else if (instantiationMapping instanceof FactoryMapping) {
tryBuilder.append(Stmt.declareVariable(toMap).named("entity")
.initializeWith(
Stmt.invokeStatic(toMap, ((FactoryMapping) instantiationMapping).getMember().getName(),
constructorParameters.toArray(new Object[constructorParameters.size()]))));
}
}
else {
// use default constructor
tryBuilder._(
Stmt.declareVariable(toMap).named("entity").initializeWith(
Stmt.nestedCall(Stmt.newObject(toMap))));
}
tryBuilder._(loadVariable("a1").invoke("recordObject",
loadVariable("objId"), loadVariable("entity")));
}
/**
*
* FIELD BINDINGS
*
*/
for (final MemberMapping memberMapping : mappingDefinition.getMemberMappings()) {
if (!memberMapping.canWrite()) continue;
if (memberMapping.getTargetType().isConcrete() && !context.isRendered(memberMapping.getTargetType())) {
context.getMarshallerGeneratorFactory().addMarshaller(memberMapping.getTargetType());
}
final Statement bindingStatement;
final Statement val;
if (memberMapping.getType().isArray()) {
val =
context.getArrayMarshallerCallback()
.demarshall(memberMapping.getType(),
extractJSONObjectProperty(memberMapping.getKey(), EJObject.class));