1515package org .jnosql .diana .couchbase .key ;
1616
1717import com .couchbase .client .java .Bucket ;
18+ import com .couchbase .client .java .document .json .JsonObject ;
1819import org .jnosql .diana .api .Value ;
1920
2021import javax .json .bind .Jsonb ;
@@ -47,13 +48,13 @@ class CouchbaseMap<K, V> implements Map<K, V> {
4748 private final String bucketName ;
4849 private final Class <K > keyClass ;
4950 private final Class <V > valueClass ;
50- private final com .couchbase .client .java .datastructures .collections .CouchbaseMap <String > map ;
51+ private final com .couchbase .client .java .datastructures .collections .CouchbaseMap <JsonObject > map ;
5152
5253 CouchbaseMap (Bucket bucket , String bucketName , Class <K > keyClass , Class <V > valueClass ) {
5354 this .bucketName = bucketName + ":map" ;
5455 this .valueClass = valueClass ;
5556 this .keyClass = keyClass ;
56- map = new com .couchbase .client .java .datastructures .collections .CouchbaseMap <>(this .bucketName , bucket );
57+ map = new com .couchbase .client .java .datastructures .collections .CouchbaseMap <JsonObject >(this .bucketName , bucket );
5758 }
5859
5960 @ Override
@@ -69,9 +70,9 @@ public boolean isEmpty() {
6970 @ Override
7071 public V get (Object key ) {
7172 Objects .requireNonNull (key , "key is required" );
72- String json = map .get (key .toString ());
73+ JsonObject json = map .get (key .toString ());
7374 if (Objects .nonNull (json )) {
74- return JSONB .fromJson (json , valueClass );
75+ return JSONB .fromJson (json . toString () , valueClass );
7576 }
7677 return null ;
7778 }
@@ -80,19 +81,19 @@ public V get(Object key) {
8081 public V put (K key , V value ) {
8182 Objects .requireNonNull (key , "key is required" );
8283 Objects .requireNonNull (value , "value is required" );
83- String json = map .put (key .toString (), JSONB .toJson (value ));
84+ JsonObject json = map .put (key .toString (), JsonObjectCouchbaseUtil .toJson (JSONB , value ));
8485 if (Objects .nonNull (json )) {
85- return JSONB .fromJson (json , valueClass );
86+ return JSONB .fromJson (json . toString () , valueClass );
8687 }
8788 return null ;
8889 }
8990
9091 @ Override
9192 public V remove (Object key ) {
9293 Objects .requireNonNull (key , "key is required" );
93- String json = map .remove (key .toString ());
94+ JsonObject json = map .remove (key .toString ());
9495 if (Objects .nonNull (json )) {
95- return JSONB .fromJson (json , valueClass );
96+ return JSONB .fromJson (json . toString () , valueClass );
9697 }
9798 return null ;
9899 }
@@ -132,18 +133,18 @@ public Set<K> keySet() {
132133 @ Override
133134 public Collection <V > values () {
134135 return map .values ().stream ()
135- .map (s -> JSONB .fromJson (s , valueClass ))
136+ .map (s -> JSONB .fromJson (s . toString () , valueClass ))
136137 .collect (toList ());
137138 }
138139
139140 @ Override
140141 public Set <Entry <K , V >> entrySet () {
141142 Map <K , V > copy = new HashMap <>();
142143
143- for (Entry <String , String > entry : map .entrySet ()) {
144+ for (Entry <String , JsonObject > entry : map .entrySet ()) {
144145 String key = entry .getKey ();
145- String value = entry .getValue ();
146- copy .put (JSONB . fromJson ( key , keyClass ), JSONB .fromJson (value , valueClass ));
146+ JsonObject value = entry .getValue ();
147+ copy .put (( K ) key , JSONB .fromJson (value . toString () , valueClass ));
147148 }
148149 return copy .entrySet ();
149150 }
0 commit comments