Boon – From Object

  • Post author:
  • Post category:Boon
  • Post comments:0 Comments
From Object

ObjectMapper class can be used to generate a JSON string from Object.

Example

The following example is using ObjectMapper class to generate a JSON string from a Student Object.

import org.boon.json.JsonFactory;
import org.boon.json.ObjectMapper;

public class BoonTester {
   public static void main(String args[]){
      ObjectMapper mapper = JsonFactory.create();      
      Student student = new Student("Zafrul", 21);
      String jsonString = mapper.writeValueAsString(student);
      System.out.println(jsonString);
   }
}
class Student {
   public String name;
   public int age;
   public Student(String name, int age) {
      this.name = name;
      this.age = age;
   }
}

Output

This produces the following output −

{"name":"Zafrul","age":21}

Next Topic:-Click Here

Leave a Reply