Convert Java object to JSON String using Jackson

Java object → JSON string

(1) Format of Class to convert Java object to JSON  String

DTO class
public  class  DTO class  {     public  String  member name 1 ;     public  String  member name 2 ; }
Execution class
public class Main {    public  Static  void  main ( String []  args )  throws  JsonProcessingException  {         DTO class  DTO instance  =  new  DTO class ();         DTO instance . Member name 1  =  value ;         DTO instance . Member name 2  =  value ;        ObjectMapper mapper = new ObjectMapper();        String json = mapper.writeValueAsString(DTO instance);        System.out.println(json);    }}

(2) Driver Program To test Java object to JSON  String conversion

Info.java
public class Info {    public String name;    public String email;}
Main.java
public class Main {    public static void main(String[] args) throws JsonProcessingException {        Info info = new Info();        info.name = "Bubble";        info.email = "bubble@interviewbubble.com";        ObjectMapper mapper = new ObjectMapper();        String json = mapper.writeValueAsString(info);        System.out.println(json);    }}
OUTPUT:
{"name":"Bubble","email":"bubble@interviewbubble.com"}