Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Support List like HashMap? #28

Closed
longtaoge opened this issue Jan 13, 2016 · 5 comments
Closed

How to Support List like HashMap? #28

longtaoge opened this issue Jan 13, 2016 · 5 comments

Comments

@longtaoge
Copy link

I want save a list in entify like HashMap

public void testSaveEntities2() throws Throwable {

    NoSQLEntity<SampleBean2> entity = new NoSQLEntity<SampleBean2>(
            "bucket", "entityId");
    SampleBean2 data = new SampleBean2();
    data.setField1("abc");
    data.setId(9);
    List<User> mUsers = new ArrayList<User>();
    for (int i = 0; i < 100; i++) {

        User mUser = new User();
        mUser.setAge("15" + i);
        mUser.setName("name" + i);
        mUsers.add(mUser);

    }

    data.setmUsers(mUsers);
    entity.setData(data);
    //NoSQL.with(context).using(SampleBean2.class).bucketId("bucket")
   // .entityId("entityId").delete();
    NoSQL.with( getInstrumentation().getTargetContext()).using(SampleBean2.class).save(entity);

}

but the result like this

image

link

How to Support List like HashMap?

@Jearil
Copy link
Owner

Jearil commented Jan 13, 2016

Unfortunately your image doesn't work so I'm not sure what your error is. By default, your data is Serialized using Gson. You will need to make sure your objects are serializable via that library. Alternatively you may create your own Serializer and Deserializer by implementing DataSerializer and DataDeserializer.

NoSQL.with(context)
  .withSerializer(serializer)
  .withDeserializer(deserializer)
  .using(SampleBean2.class)
  .save(entity);

@longtaoge
Copy link
Author

the Serialized is ok and i am use the Gson also , my mean is if a entity contains a long list ,like SampleBean2 ' entity ,the entity will save as a long json String in DB ,eg : if the list 's size is big than 1000, sqlite will save the String failure.

@Jearil
Copy link
Owner

Jearil commented Jan 17, 2016

Ok. I'll work on changing the DB to store a byte array which would be
better.

On Sun, Jan 17, 2016, 2:45 AM longtaoger notifications@github.com wrote:

the Serialized is ok and i am use the Gson also , my mean is if a entity
contains a long list ,like SampleBean2 ' entity ,the entity will save as a
long json String in db ,eg : if the list 's size is big than 1000, sqlite
will save the String failure.


Reply to this email directly or view it on GitHub
#28 (comment).

@longtaoge
Copy link
Author

that may be good idea , i tested the hawk can saved more data on once I/O

@Jearil
Copy link
Owner

Jearil commented Jan 28, 2016

Saving as a byte[] is now in the github. You can build your own copy of the library and try that until I publish a new build to sonatype.

@Jearil Jearil closed this as completed Jan 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants