Java object to json using Jackson example



Program


import java.io.File;
import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.JasonProjectDeomo.bean.Address;
import com.JasonProjectDeomo.bean.Person;

public class JavaObjectToJsonFile {
public static void main(String[] args) throws JsonGenerationException,
JsonMappingException, IOException {
Address address = new Address("Dhananjaypur", "Varanasi", "UP");
Person person = new Person(1, "Arvind", address);
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(new File("JacksonFile/dataFour.json"), person);
System.out.println("--Done--");
}
}



Output

--Done--



Related Post

Comments


©candidjava.com