/**
  * Method to prepare Complex type representation.
  *
  * @param writer
  * @param entityMetadata
  * @param propertyName
  * @param propertiesList
  * @param modelName
  */
 private void writePropertyComplexList(
     StreamWriter writer,
     EntityMetadata entityMetadata,
     EntityProperty property,
     String modelName) {
   @SuppressWarnings("unchecked")
   List<EntityProperties> propertiesList = (List<EntityProperties>) property.getValue();
   String name = entityMetadata.getEntityName() + "_" + property.getName();
   int parseCount = 0;
   for (EntityProperties properties : propertiesList) {
     String fqTypeName = modelName + Metadata.MODEL_SUFFIX + "." + name;
     // We should be able to differentiate List<ComplexType> with regular ComplexType
     if (entityMetadata.isPropertyList(property.getFullyQualifiedName())) {
       if (parseCount == 0) {
         writer.startElement(new QName(d, name, "d"));
         writer.writeAttribute(new QName(m, "type", "m"), "Bag(" + fqTypeName + ")");
         writer.startElement(new QName(d, "element", "d"));
         parseCount++;
       } else {
         writer.startElement(new QName(d, "element", "d"));
       }
     } else {
       writer.startElement(new QName(d, name, "d"));
       writer.writeAttribute(new QName(m, "type", "m"), fqTypeName);
     }
     writeProperties(writer, entityMetadata, properties, modelName);
     writer.endElement();
   }
   // For List<ComplexTypes> we should end the complex node here
   if (!propertiesList.isEmpty()
       && entityMetadata.isPropertyList(property.getFullyQualifiedName())) {
     writer.endElement();
   }
 }
 private void writeProperty(
     StreamWriter writer, EntityMetadata entityMetadata, EntityProperty property) {
   String elementText = entityMetadata.getPropertyValueAsString(property);
   writer.startElement(new QName(d, property.getName(), "d"));
   EdmType type =
       MetadataOData4j.termValueToEdmType(
           entityMetadata.getTermValue(property.getFullyQualifiedName(), TermValueType.TERM_NAME));
   boolean isNullable = entityMetadata.isPropertyNullable(property.getFullyQualifiedName());
   // Append Type Attribute
   if (!type.equals(EdmSimpleType.STRING)) {
     writer.writeAttribute(new QName(m, "type", "m"), type.getFullyQualifiedTypeName());
   }
   // Append Null attribute
   if (isNullable && (elementText.isEmpty()) && !type.equals(EdmSimpleType.STRING)) {
     writer.writeAttribute(new QName(m, "null", "m"), "true");
   }
   // Write the property text
   if (type.equals(EdmSimpleType.DATETIME) && !elementText.isEmpty()) {
     // Write dates in UTC format
     SimpleDateFormat formatUTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
     formatUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
     writer.writeElementText(formatUTC.format((Date) property.getValue()));
   } else if (elementText != null) {
     writer.writeElementText(elementText);
   }
   writer.endElement();
 }