Skip to content

Commit

Permalink
Add @odata.type properties in TableEntity.addProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Siegel committed Aug 29, 2020
1 parent 3a1d08c commit cb8d2b6
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.data.tables.implementation.EntityDataModelType;
import com.azure.data.tables.implementation.TablesConstants;
import com.azure.data.tables.implementation.TablesModelHelper;

Expand Down Expand Up @@ -144,9 +145,23 @@ public TableEntity addProperty(String key, Object value) {
} else if (TablesConstants.ROW_KEY.equals(key)) {
throw logger.logExceptionAsError(
new IllegalArgumentException(TablesConstants.ROW_KEY + " cannot be set after object creation."));
} else if (TablesConstants.TIMESTAMP_KEY.equals(key)) {
throw logger.logExceptionAsError(
new IllegalArgumentException(key + " is a reserved property."));
} else if (TablesConstants.METADATA_KEYS.contains(key)) {
throw logger.logExceptionAsError(
new IllegalArgumentException(key + " is a reserved property."));
}

properties.put(key, value);
if (value == null) {
properties.put(key + TablesConstants.ODATA_TYPE_KEY_SUFFIX, TablesConstants.ODATA_TYPE_NULL);
} else {
EntityDataModelType type = EntityDataModelType.forClass(value.getClass());
if (type != null) {
properties.put(key + TablesConstants.ODATA_TYPE_KEY_SUFFIX, type.getEdmType());
}
}
return this;
}

Expand Down

0 comments on commit cb8d2b6

Please sign in to comment.