public static Statement demarshal(final MetaClass type, final Statement statement, final String accepts) { Statement demarshallingStatement = null; if (PrimitiveTypeMarshaller.canHandle(type, accepts)) { demarshallingStatement = PrimitiveTypeMarshaller.demarshal(type, statement); } else { if (!type.equals(MetaClassFactory.get(void.class))) { if (type.isAssignableTo(Map.class)) { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement, type.asBoxed().asClass(), MarshallingGenUtil.getConcreteMapKeyType(type.asBoxed()), MarshallingGenUtil.getConcreteMapValueType(type.asBoxed())); } else { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement, type.asBoxed().asClass(), MarshallingGenUtil.getConcreteElementType(type.asBoxed())); } } else { demarshallingStatement = Stmt.invokeStatic(MarshallingWrapper.class, "fromJSON", statement); } } return demarshallingStatement; }
public Statement maybeAddAssumedTypes(BlockBuilder<?> blockBuilder, String varName, Mapping mapping, Statement statement) { final MetaClass elementType = MarshallingGenUtil.getConcreteCollectionElementType(mapping.getType()); final MetaClass mapKeyType = MarshallingGenUtil.getConcreteMapKeyType(mapping.getType()); final MetaClass mapValueType = MarshallingGenUtil.getConcreteMapValueType(mapping.getType()); boolean assumedMapTypesSet = false; if (elementType != null) { blockBuilder.append(Stmt.loadVariable("a1").invoke("setAssumedElementType", elementType.getFullyQualifiedName())); } else if (mapKeyType != null && mapValueType != null) { blockBuilder.append(Stmt.loadVariable("a1").invoke("setAssumedMapKeyType", mapKeyType.getFullyQualifiedName())); blockBuilder.append(Stmt.loadVariable("a1") .invoke("setAssumedMapValueType", mapValueType.getFullyQualifiedName())); assumedMapTypesSet = true; } if (varName != null) { blockBuilder.append(Stmt.declareFinalVariable(varName, mapping.getTargetType(), statement)); } else { blockBuilder.append(statement); } if (assumedMapTypesSet) { blockBuilder.append(Stmt.loadVariable("a1").invoke("resetAssumedTypes")); } return (varName != null) ? Stmt.loadVariable(varName) : statement; }
public Statement maybeAddAssumedTypes(BlockBuilder<?> blockBuilder, String varName, Mapping mapping, Statement statement) { final MetaClass elementType = MarshallingGenUtil.getConcreteCollectionElementType(mapping.getType()); final MetaClass mapKeyType = MarshallingGenUtil.getConcreteMapKeyType(mapping.getType()); final MetaClass mapValueType = MarshallingGenUtil.getConcreteMapValueType(mapping.getType()); boolean assumedMapTypesSet = false; if (elementType != null) { blockBuilder.append(Stmt.loadVariable("a1").invoke("setAssumedElementType", elementType.getFullyQualifiedName())); } else if (mapKeyType != null && mapValueType != null) { blockBuilder.append(Stmt.loadVariable("a1").invoke("setAssumedMapKeyType", mapKeyType.getFullyQualifiedName())); blockBuilder.append(Stmt.loadVariable("a1") .invoke("setAssumedMapValueType", mapValueType.getFullyQualifiedName())); assumedMapTypesSet = true; } if (varName != null) { blockBuilder.append(Stmt.declareFinalVariable(varName, mapping.getTargetType(), statement)); } else { blockBuilder.append(statement); } if (assumedMapTypesSet) { blockBuilder.append(Stmt.loadVariable("a1").invoke("resetAssumedTypes")); } return (varName != null) ? Stmt.loadVariable(varName) : statement; }