diff --git a/engine/src/main/java/com/arcadedb/database/DetachedDocument.java b/engine/src/main/java/com/arcadedb/database/DetachedDocument.java index b835c7edf..5e61314ee 100644 --- a/engine/src/main/java/com/arcadedb/database/DetachedDocument.java +++ b/engine/src/main/java/com/arcadedb/database/DetachedDocument.java @@ -22,6 +22,11 @@ import java.util.*; +/** + * Detached document instances are generated from a document and can be accessed outside a transaction. + * + * @author Luca Garulli (l.garulli@arcadedata.com) + */ public class DetachedDocument extends ImmutableDocument { private Map map; diff --git a/engine/src/main/java/com/arcadedb/serializer/BinarySerializer.java b/engine/src/main/java/com/arcadedb/serializer/BinarySerializer.java index a4333c1be..da31de08b 100644 --- a/engine/src/main/java/com/arcadedb/serializer/BinarySerializer.java +++ b/engine/src/main/java/com/arcadedb/serializer/BinarySerializer.java @@ -452,9 +452,16 @@ else if (value instanceof LocalDate) content.putUnsignedNumber(length); for (int i = 0; i < length; ++i) { final Object entryValue = Array.get(value, i); - final byte entryType = BinaryTypes.getTypeFromValue(entryValue); - content.putByte(entryType); - serializeValue(database, content, entryType, entryValue); + try { + final byte entryType = BinaryTypes.getTypeFromValue(entryValue); + content.putByte(entryType); + serializeValue(database, content, entryType, entryValue); + } catch (Exception e) { + LogManager.instance().log(this, Level.SEVERE, "Error on serializing array value for element %d = '%s'", + i, entryValue); + throw new SerializationException( + "Error on serializing array value for element " + i + " = '" + entryValue + "'"); + } } } break; @@ -462,33 +469,40 @@ else if (value instanceof LocalDate) case BinaryTypes.TYPE_MAP: { final Dictionary dictionary = database.getSchema().getDictionary(); - if( value instanceof JSONObject) + if (value instanceof JSONObject) value = ((JSONObject) value).toMap(); final Map map = (Map) value; content.putUnsignedNumber(map.size()); for (final Map.Entry entry : map.entrySet()) { - // WRITE THE KEY - Object entryKey = entry.getKey(); - byte entryKeyType = BinaryTypes.getTypeFromValue(entryKey); - - if (entryKey != null && entryKeyType == BinaryTypes.TYPE_STRING) { - final int id = dictionary.getIdByName((String) entryKey, false); - if (id > -1) { - // WRITE THE COMPRESSED STRING AS MAP KEY - entryKeyType = BinaryTypes.TYPE_COMPRESSED_STRING; - entryKey = id; + try { + // WRITE THE KEY + Object entryKey = entry.getKey(); + byte entryKeyType = BinaryTypes.getTypeFromValue(entryKey); + + if (entryKey != null && entryKeyType == BinaryTypes.TYPE_STRING) { + final int id = dictionary.getIdByName((String) entryKey, false); + if (id > -1) { + // WRITE THE COMPRESSED STRING AS MAP KEY + entryKeyType = BinaryTypes.TYPE_COMPRESSED_STRING; + entryKey = id; + } } - } - content.putByte(entryKeyType); - serializeValue(database, content, entryKeyType, entryKey); - - // WRITE THE VALUE - final Object entryValue = entry.getValue(); - final byte entryValueType = BinaryTypes.getTypeFromValue(entryValue); - content.putByte(entryValueType); - serializeValue(database, content, entryValueType, entryValue); + content.putByte(entryKeyType); + serializeValue(database, content, entryKeyType, entryKey); + + // WRITE THE VALUE + final Object entryValue = entry.getValue(); + final byte entryValueType = BinaryTypes.getTypeFromValue(entryValue); + content.putByte(entryValueType); + serializeValue(database, content, entryValueType, entryValue); + } catch (Exception e) { + LogManager.instance().log(this, Level.SEVERE, "Error on serializing map value for key '%s' = '%s'", + entry.getKey(), entry.getValue()); + throw new SerializationException( + "Error on serializing map value for key '" + entry.getKey() + "' = '" + entry.getValue() + "'"); + } } break; }