I'am reading articles about them but it confuses me. What is the difference between the two?
Which is one is better to use?
I have my JSON..how can JACKSON Help me with my parsing?
I'am reading articles about them but it confuses me. What is the difference between the two?
Which is one is better to use?
I have my JSON..how can JACKSON Help me with my parsing?
You cannot compare Jackson and JSON. Jackson is the library for processing JSON data.
Jackson is a multi-purpose Java library for processing JSON data format. Jackson aims to be the best possible combination of fast, correct, lightweight, and ergonomic for developers.
JSON is a data format, Jackson is a Java library for creating and parsing JSON.
Jackson is a library that operate on JSON
JSON stands for javascript object notation and it is a data format
JavaScript Object Notation, is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is used primarily to transmit data between a server and web application, as an alternative to XML.
From Jackson home page: Jackson is a:
Below you can find simple example how to deserialize your JSON data to Java POJO classes:
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
public class JacksonProgram {
public static void main(String[] args) throws Exception {
URL osurceUrl = new URL("http://app-dlslsg.azurewebsites.net/json/postList.php");
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
PostList postList = mapper.readValue(osurceUrl, PostList.class);
System.out.println(postList);
}
}
class PostList {
private List<Post> post;
public List<Post> getPost() {
return post;
}
public void setPost(List<Post> post) {
this.post = post;
}
@Override
public String toString() {
return Joiner.on(System.getProperty("line.separator")).join(post);
}
}
class Post {
private int id;
private String body;
private String image;
private Calendar stamp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public Calendar getStamp() {
return stamp;
}
public void setStamp(Calendar stamp) {
this.stamp = stamp;
}
@Override
public String toString() {
return "Post [id=" + id + ", body=" + body + ", image=" + image + ", stamp=" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(stamp.getTime()) + "]";
}
}
Above program prints:
Post [id=101, body=google, image=http://app-dlslsg.azurewebsites.net/images/google.png, stamp=2013-11-18 12:12:02]
Post [id=61, body=facebook, image=http://app-dlslsg.azurewebsites.net/images/facebook.png, stamp=2013-11-16 13:28:35]
Post [id=111, body=Calendar, image=http://app-dlslsg.azurewebsites.net/images/ical.png, stamp=2013-11-18 12:12:14]
Post [id=121, body=Outlook, image=http://app-dlslsg.azurewebsites.net/images/outlook.png, stamp=2013-11-18 12:12:21]
Post [id=131, body=USG, image=http://app-dlslsg.azurewebsites.net/images/1472825_453923301384770_1942535278_n.jpg, stamp=2013-11-18 12:24:30]
Post [id=231, body=http://dlsu-usg.com/activities/dare-for-10-extended/
WE DARE YOU… To make a change in someone’s life now.
The Office of the Vice President for External Affairs and BLAZE 2013 brings you “DARE FOR TEN" EXTENDED!!!
Your TEN PESOS can make a d, image=http://app-dlslsg.azurewebsites.net/, stamp=2013-11-27 14:47:24]
Post [id=241, body=http://tours.wowbatangas.com/files/2011/01/IMG_6018.jpg, image=http://app-dlslsg.azurewebsites.net/, stamp=2014-01-03 16:06:31]
Post [id=251, body=iTRAVELpost, image=http://app-dlslsg.azurewebsites.net/images/ic_launcher-web.png, stamp=2014-01-10 08:53:19]