android - Using Jackson to deserialize JSON objects to POJOs -
i'm trying use jackson in android project via objectmapper.
my pojo follows:
public class product { @jsonproperty("title") string title; @jsonproperty("vendor") string vendor; public void settitle(string title){ this.title = title; } public void setvendor(string vendor){ this.vendor = vendor; } public string gettitle() { return title; } public string getvendor() { return vendor; } }
i've written unit test see if jackson working deserialize json objects.
context ctx; public void setup() throws exception { super.setup(); ctx = getcontext(); } public void testconvertjsontoproduct() throws exception { objectmapper m = new objectmapper(); product product = m.readvalue(ctx.getassets().open("foo.json"), product.class); assertequals("macbook", product.gettitle()); }
my actual json file contains more information i've set in product, want working. using larger file causes product created it's values set null. thought might because of data in there, created file (foo.json) contains following:
{"title" : "macbook", "vendor" : "apple"}
with getting same problem.
note not need @jsonproperty annotations, since have getters , setters imply "title" (as per bean naming convention). either way, code should work have shown.
i verify first ctxt.getassets().open() not return empty content? that's thing stands out.
Comments
Post a Comment