Skip to content

Commit 0edcc0a

Browse files
committed
fixes map
1 parent 6fd509a commit 0edcc0a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

couchbase-driver/src/main/java/org/jnosql/diana/couchbase/key/CouchbaseMap.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,7 @@ public Collection<V> values() {
136136
Collection<V> values = new ArrayList<>();
137137

138138
for (Object object : map.values()) {
139-
if(object instanceof Map) {
140-
values.add(JSONB.fromJson(JsonObject.from(Map.class.cast(object)).toString(), valueClass));
141-
} else if(object instanceof JsonObject) {
142-
values.add(JSONB.fromJson(JsonObject.class.cast(object).toString(), valueClass));
143-
}
139+
values.add(convertValue(object));
144140
}
145141
return values;
146142
}
@@ -151,9 +147,19 @@ public Set<Entry<K, V>> entrySet() {
151147

152148
for (Entry<String, JsonObject> entry : map.entrySet()) {
153149
String key = entry.getKey();
154-
JsonObject value = entry.getValue();
155-
copy.put((K) key, JSONB.fromJson(value.toString(), valueClass));
150+
V value = convertValue(entry.getValue());
151+
copy.put((K) key, value);
156152
}
157153
return copy.entrySet();
158154
}
155+
156+
private V convertValue(Object value) {
157+
if(value instanceof Map) {
158+
return JSONB.fromJson(JsonObject.from(Map.class.cast(value)).toString(), valueClass);
159+
} else if(value instanceof JsonObject) {
160+
return JSONB.fromJson(JsonObject.class.cast(value).toString(), valueClass);
161+
}
162+
163+
throw new IllegalStateException("Couchbase does not support the structure value " + value.getClass().getName());
164+
}
159165
}

0 commit comments

Comments
 (0)