Support for List #33
Comments
You can either convert your list into an array ArrayList#toArray(T[]) then save it. (check snappyDB = DBFactory.open(getContext(), dbName);
List<Book> books = new ArrayList<>(3);
books.add(new Book("Echo Burning", "0-399-14726-8"));
books.add(new Book("Nothing To Lose", "0-593-05702-3"));
books.add(new Book("61 Hours", "978-0-593-05706-3"));
snappyDB.put("books", books);
ArrayList<Book> mySavedBooks = (ArrayList<Book>) snappyDB.getObject("books", ArrayList.class);
assertNotNull(mySavedBooks);
assertEquals(mySavedBooks.size(), books.size());
assertEquals(books.get(0).hashCode(), mySavedBooks.get(0).hashCode());
assertEquals(books.get(1).hashCode(), mySavedBooks.get(1).hashCode());
assertEquals(books.get(2).hashCode(), mySavedBooks.get(2).hashCode()); cheers |
@nhachicha |
Hi, |
Hello, I want to save an ArrayList of objects into the SnappyDB and retrieve it, when necessary. I follow the instructions as given and the arrayList is saved, but when I try to retrieve it from the DB, the error caught is : "Maybe you tried to retrieve an array using this method ? please use getObjectArray instead Class cannot be created (missing no-arg constructor): com.google.gson.JsonPrimitive".
Any ideas? |
@SophieKrt |
Thank you , I will try to save my objects this way. |
Hi,
This library already looks great, but I have read all the docs you provided but I didn't read anywhere that this library supports any type of List like Array List etc.
Can you please let me know if it supports?
Thank you.
The text was updated successfully, but these errors were encountered: