google-code-export / protostuff

Automatically exported from code.google.com/p/protostuff
Apache License 2.0
1 stars 1 forks source link

RuntimeSchema.getSchema on Android and Server #77

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
public class UserAccount {

    private String username;
    private String password;
}

Server
Schema<UserAccount> schema = RuntimeSchema.getSchema(UserAccount.class);
        byte[] protostuff;
        // protostuff serializeFI
        try {
            protostuff = ProtostuffIOUtil.toByteArray(userAccount, schema, buffer);

Android 
Schema<UserAccount> schema = RuntimeSchema.getSchema(UserAccount.class);

        UserAccount userAccount = new UserAccount();
        try {
            ProtostuffIOUtil.mergeFrom(str.getBytes(), userAccount, schema);
        } finally {
            buffer.clear();

What is the expected output? What do you see instead?
The values are reconstructed in a wrong order.
User name on the server becomes the password on the android and vice versa

What version of the product are you using? On what operating system?
Android 2.2,JDK 6

Please provide any additional information below.
tried both protostuff-rumetime-md,protostuff-rumetime on the server same 
behaviour

Original issue reported on code.google.com by pohzysg on 23 Jul 2011 at 2:20

GoogleCodeExporter commented 9 years ago
There's a possibility that android's reflection api returns the wrong field 
ordering on android.

I've actually tested on android 2.3.3 and the field ordering was correct.
Can you test on yours?  Print out the text output on android via new 
String(YamlIOUtil.toByteArray(userAccount, schema, buffer));

Original comment by david.yu...@gmail.com on 23 Jul 2011 at 2:30

GoogleCodeExporter commented 9 years ago
Kindly see the output below. Thanks.

07-23 15:02:16.401: INFO/System.out(329): --- !UserAccount
07-23 15:02:16.401: INFO/System.out(329): password: username
07-23 15:02:16.410: INFO/System.out(329): username: password

Original comment by pohzysg on 23 Jul 2011 at 3:03

GoogleCodeExporter commented 9 years ago
Thanks.  Will try to reproduce.  I'm assuming that output is from the emulator.

Original comment by david.yu...@gmail.com on 23 Jul 2011 at 3:19

GoogleCodeExporter commented 9 years ago
Yes that’s right. Thanks for all the effort.

Original comment by pohzysg on 23 Jul 2011 at 3:38

GoogleCodeExporter commented 9 years ago
I tried this on 2.3.3 and it had no problems.
Can you try on 2.3.3 to see if protostuff is really the culprit here?

Original comment by david.yu...@gmail.com on 31 Jul 2011 at 9:32

GoogleCodeExporter commented 9 years ago
I tried it on 2.3.3 ,but I am facing the same issue.
But when I used a custom schema it is fine. Attached for your reference.
By the way, my server is running on JDK 1.6u26. Do let me know if you 
require more information.

Original comment by pohzysg on 31 Jul 2011 at 3:07

GoogleCodeExporter commented 9 years ago
I tested mine on java1.6u26, windows xp.  What os did you use for testing?
I dont' see the attached project.  Can you attach the whole example project?

Original comment by david.yu...@gmail.com on 1 Aug 2011 at 2:08

GoogleCodeExporter commented 9 years ago
Related to issue 86.

Original comment by david.yu...@gmail.com on 21 Oct 2011 at 5:39

GoogleCodeExporter commented 9 years ago
I haven't seen the non-deterministic ordering actually happening on my Android 
devices (not tested much either I must say), but from what I have read around, 
it does happen on some devices running Dalvik and break frameworks relying on 
consistent field order.  To be on the safe side, I decided to implement, as 
suggested in the comments for issue 86, an extension to the runtime schema 
where the field mapping/tag can be enforced via an annotation.

I am attaching the patch in case anyone is interested, but I am just starting 
to use it so use it at your own risk! If there is any interest to bring that 
upstream, please review, and I will iterate.

From a documentation perspective, until this patch or something similar gets 
into trunk, I think this known issue should be highlighted on the home page, 
since Android is specifically mentioned as a fit for runtime-md but we do know 
it won't work in all cases because of the weak reflection contract.

Original comment by bjag...@gmail.com on 18 Mar 2012 at 9:49

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Brice,

Thanks for the patch.  Will review it and include for the next release.

Cheers

Original comment by david.yu...@gmail.com on 25 Mar 2012 at 11:45

GoogleCodeExporter commented 9 years ago
patch added @ rev 1460.  Thanks!

Original comment by david.yu...@gmail.com on 29 Mar 2012 at 6:09

GoogleCodeExporter commented 9 years ago
1.0.5 fixed this (forgot to close)

Original comment by david.yu...@gmail.com on 30 Apr 2012 at 2:33