private static Map<String, Object> getProperties(Entity entity)
throws IOException, ClassNotFoundException {
if (entity == null) {
return null;
}
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
for (String property : entity.getNames()) {
if (entity.getValue(property) instanceof StringValue) {
builder.put(property, (String) entity.getString(property));
} else if (entity.getValue(property) instanceof LongValue) {
builder.put(property, new Long(entity.getLong(property)).intValue());
} else if (entity.getValue(property) instanceof DoubleValue) {
builder.put(property, (Double) entity.getDouble(property));
} else if (entity.getValue(property) instanceof BooleanValue) {
builder.put(property, (Boolean) entity.getBoolean(property));
} else if (entity.getValue(property) instanceof TimestampValue) {
builder.put(property, (Timestamp) entity.getTimestamp(property));
} else {
Blob blob = entity.getBlob(property);
Object obj = null;
try (ObjectInputStream in = new ObjectInputStream(blob.asInputStream())) {
obj = in.readObject();
}
builder.put(property, obj);
}
}
return builder.build();
}