Thanks for the hint Mark - we'll try that as well.

Btw we just wanted to let everyone know that we've tried latest trunk code
from

http://fisheye.codehaus.org/browse/jackson/  (just pick the binary tarball
links in the bottom lefthand corner, install and, go to directory, and do
'ant dist' - then pickup jar from dist directory - we used lgpl version.
Then use the code we submitted below. But you will need to patch a few
classes in the jackson json code becuase they are referencing classes that
don't exist in android - for e.g. XMLGregorianCalendar . Whenever you get a
no classdef found error using this framework, go to that line in code,
comment it out, do ant clean/ant dist again, remove the library from
classpath in eclipse, add it again so that eclipse android plugin will
package it again inside your android project - rinse, repeast. You will need
to do this in two classes I think, and at 3-4 different places - you won't
have to comment out a LOT of code - if this works without any issues, we can
try talking to the author so that we can have compatibility with android. So
far, we can serialise/deserialise very complex objects to JSON successfully)

(http://www.cowtowncoder.com/hatchery/jackson/  - now partof codehaus)

For hints on how to use, checkout source, our example below, or
http://www.cowtowncoder.com/blog/archives/2008/12/entry_121.html  (and
related entries)


public class Customer implements Serializable{

    private int x;
    private int y;
    public String s = "Hello";
    public List<String> ary = new ArrayList<String>();
    public List<String> ary2 = new ArrayList<String>();
    public Set<String> set = new HashSet<String>();

    public Customer(){
        set.add(new String("Yarrr!"));
        ary.add(new String("Savvy?"));
    }
 // not the whole class, add getters and setters
}

public class User implements java.io.Serializable {

    private Long userid;
    private String username;
    private String password;
    private String firstname;
    private String middlename;
    private String lastname;
    public String s;
    private Long chatlistid;
    private Long latitude;
    private Long longitude;
    private Set<Object> events = new HashSet<Object>(0);
    private Set<Object> addresses = new HashSet<Object>(0);
    private Set<Object> mails = new HashSet<Object>(0);
    private Set<Object> groups = new HashSet<Object>(0);
    private Set<Object> requests = new HashSet<Object>(0);
    private Set<Object> chatmessages = new HashSet<Object>(0);
    private Set<Object> broadcasts = new HashSet<Object>(0);
    private Set<Object> albums = new HashSet<Object>(0);
    private Set<Object> todos = new HashSet<Object>(0);
    private Set<Object> subscriptions = new HashSet<Object>(0);
    private Set<Object> avatars = new HashSet<Object>(0);
    private Set<Object> notes = new HashSet<Object>(0);
    private Customer c = new Customer();

// not the whole class, add getters and setters/empty constructor


}


// some arbitrary place in android - e.g. code executed in response to a
DoIT button....

                User aTestObj = new User();
                ObjectMapper aMapper  = new ObjectMapper();
                StringWriter aWriter = new StringWriter();
                JsonGenerator aGen;
                try {
                    aGen = new JsonFactory().createJsonGenerator(aWriter);
                    aMapper.writeValue(aGen, aTestObj);
                    aGen.close();
                    System.out.println(aWriter.toString());

                    User result = new
ObjectMapper().readValue(aWriter.toString(), User.class);
                    System.out.println(result);  // doesn't really do
anything, just debug this line
                     // to find out if you got back the original object or
not - yes I'm lazy

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


On Sat, Jan 10, 2009 at 12:52 PM, Mark Murphy <[email protected]>wrote:

>
>
>
> Apache Thrift works on Android, at least in terms of their data
> marshalling code.
>
> http://incubator.apache.org/thrift/
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com
> _The Busy Coder's Guide to Android Development_ Version 2.0 Published!
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to