jackson mini json to object class

I was added "jackson-mini-1.9.2.jar"(is not "jackson-all-1.9.2.jar") in my project, I want to convert json to object class.

Use "jackson-all-1.9.2.jar",we can use "ObjectMapper" to get it. but use "jackson-mini-1.9.2.jar",How to do it?

If I write the follow code"

    String json = "{\"name\" : {\"first\" : \"Joe\", \"last\" : \"Sixpack\" }, \"gender\" : \"MALE\",   \"verified\" : false,   \"userImage\" : \"Rm9vYmFyIQ==\" }";
    JsonFactory f = new JsonFactory();
    JsonParser jp = f.createJsonParser(json);

    User user = jp.readValueAs(User.class);

The result is like that:

Exception in thread "main" java.lang.IllegalStateException: No ObjectCodec defined for the parser, can not deserialize JSON into Java objects at org.codehaus.jackson.JsonParser.readValueAs(Unknown Source) at TestJackson.main(TestJackson.java:21)

Answers


You can implement your own ObjectCodec and then register it with the JsonFactory by calling JsonFactory#setCodec(myCodec).

Or (much easier!), just get hold of jackson-mapper-1.9.2.jar and add it to your classpath, so that you can use the default ObjectMapper.


Need Your Help

Select Output in User Defined Function in R

r function output user-defined-functions

I have written a function that produces as output 2 matrices, say A & B, and I have used list() in order to separate them in my output. Now I would like to re-write my function so that the disp...

Multivariate Testing with Optimizely

javascript multivariate-testing optimizely

I've just started using Optimizely, and really love it. However, I need to do a multivariate test. Has anyone come up with a way, hack or otherwise, to do MVT in Optimizely? Manually creating 25-100

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.