JSON Tutorial

Json Array to String Array Using Jackson Example

Json Array to String Array:

Here is a simple example program for how to converting Json Array to String Array using jackson.

package com.JasonProjectDeomo.Jackson.JsonRead;

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

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;

import com.JasonProjectDeomo.bean.Person;

public class JsonFileToJavaStringArray {
  public static void main(String[] args) throws JsonParseException,
      JsonMappingException, IOException {

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true);
    // read from string variable
    Person person = mapper.readValue(new File("JacksonFile/dataOne.json"),
        Person.class);
    String jsonString = mapper.writeValueAsString(person);
    System.out.println(jsonString);
  }

}

Output

{"id":1,"name":"Arvind","address":{"village":"Dhananjaypur","district":"Varanasi","state":"UP"}}

--Done--