public static Object fieldTypeFromStream(
      final ODocument iDocument, OType iType, final Object iValue) {
    if (iValue == null) return null;

    if (iType == null) iType = OType.EMBEDDED;

    switch (iType) {
      case STRING:
      case INTEGER:
      case BOOLEAN:
      case FLOAT:
      case DECIMAL:
      case LONG:
      case DOUBLE:
      case SHORT:
      case BYTE:
      case BINARY:
      case DATE:
      case DATETIME:
      case LINK:
        return simpleValueFromStream(iValue, iType);

      case EMBEDDED:
        // EMBEDED RECORD
        return ((ODocument) OStringSerializerEmbedded.INSTANCE.fromStream((String) iValue))
            .addOwner(iDocument);

      case CUSTOM:
        // RECORD
        final Object result = OStringSerializerAnyStreamable.INSTANCE.fromStream((String) iValue);
        if (result instanceof ODocument) ((ODocument) result).addOwner(iDocument);
        return result;

      case EMBEDDEDSET:
      case EMBEDDEDLIST:
        {
          final String value = (String) iValue;
          return ORecordSerializerSchemaAware2CSV.INSTANCE.embeddedCollectionFromStream(
              iDocument, iType, null, null, value);
        }

      case EMBEDDEDMAP:
        {
          final String value = (String) iValue;
          return ORecordSerializerSchemaAware2CSV.INSTANCE.embeddedMapFromStream(
              iDocument, null, value, null);
        }
    }

    throw new IllegalArgumentException(
        "Type " + iType + " not supported to convert value: " + iValue);
  }