Checkout for Promo Codes

Jackson API client - how to read json from URL?

This page shows how to read Json data from JSON API URLs using jackson APIs.

Note: Refer How to convert Java object to JSON string? page for dependent libraries.

Here is the input json file:

Json Input from URL:
  "userId": 1,
  "id": 7,
  "title": "magnam facilis autem",
  "body": "dolore placeat quibusdam ea quo vitae"

package com.java2novice.json;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.java2novice.models.Post;

public class ReadJsonEx {

	public static void main(String a[]){
		ObjectMapper mapper = new ObjectMapper();
		try {
			Post usrPost = mapper.readValue(new URL(""), Post.class);
		} catch (IOException e) {
			// TODO Auto-generated catch block

package com.java2novice.models;

public class Post {

	private int userId;
	private int id;
	private String title;
	private String body;
	public int getUserId() {
		return userId;

	public void setUserId(int userId) {
		this.userId = userId;

	public int getId() {
		return id;

	public void setId(int id) { = id;

	public String getTitle() {
		return title;

	public void setTitle(String title) {
		this.title = title;

	public String getBody() {
		return body;

	public void setBody(String body) {
		this.body = body;

	public String toString(){
		return this.userId+" | " +" | "+this.title+" | "+this.body; 

1 | 7 | magnam facilis autem | dolore placeat quibusdam ea quo vitae
<< Previous Program 

Jackson JSON examples

  1. How to convert Java object to JSON string?
  2. How to convert JSON string to Java object?
  3. How to convert JSON string to Map using Jackson API?
  4. How to convert Map to JSON string using Jackson API?
  5. Enable JSON pretty print using Jackson API
  6. How to rename JSON properties using Jackson annotations?
  7. How to ignore JSON property using Jackson annotations?
  8. How to order JSON elements using Jackson annotations?
  9. How to ignore json empty or null values using Jackson API in java?
  10. How to handle date in Json using Jackson api in java?
  11. How to read specific json node in Jackson api (tree model)?
  12. Jackson API client - how to read json from URL?
Knowledge Centre
Can you list serialization methods?
Serialization interface does not have any methods. It is a marker interface. It just tells the JVM that your class can be serializable.
Famous Quotations
I respect faith, but doubt is what gets you an education.
-- Wilson Mizner

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2020 by Nataraja Gootooru. All Rights Reserved.