Convert Java Object to JSON String | Code Factory

Donate : Link

Medium Blog : Link

Applications : Link

Download Code and Jars : Link

File :

package com.codeFactory.bean;

public class EmployeeBean {

	private int id;
	private String name;
	private String gender;
	private String designation;

	// Getters and Setters...

File :

package com.codeFactory.main;

import java.util.HashMap;
import java.util.Map;
import com.codeFactory.bean.EmployeeBean;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
	public static void main(String args[]) {
		EmployeeBean employeeBean = new EmployeeBean();
		ObjectMapper objectMapper = new ObjectMapper();

		Map<String, String> map = new HashMap<String, String>();
		map.put("1", "Welcome");
		map.put("2", "to");
		map.put("3", "Code Factory");

		try {
			String jsonStr = objectMapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s