1

Below shown is my JSONdata ,i want to create POJO class for my JSONdata/JSONResponse. how to handle using jsonschema2pojo,i don't want to use any online tool i need source code to work on. ex: JSONdata

 [ {
      "ADDRESS" : "ewrer23214324",
      "DESCP" : "LO-3434",
      "DEVICE size" : "1.01091E+11",
      "DIRECTORY NUMBER  1" : "\\+34343"
      } ]
sharan
  • 63
  • 1
  • 10
  • 2
    Possible duplicate of [Create a POJO using JSON data](http://stackoverflow.com/questions/26271526/create-a-pojo-using-json-data) – bananas Sep 19 '16 at 03:47
  • Possible duplicate of [Generate Java class from JSON?](http://stackoverflow.com/questions/1957406/generate-java-class-from-json) – Mehdi Dehghani Sep 19 '16 at 04:10

1 Answers1

0

First,I have question in "\+34343" ,it is illegal.I consider "+34343". I use jackson.

public class Poj implements Serializable{

    @JsonProperty("ADDRESS")
    private String address;
    @JsonProperty("DESCP")
    private String descp;
    @JsonProperty("DEVICE size")
    private Double deviceSize;
    @JsonProperty("DIRECTORY NUMBER 1")
    private Long directoryNumberOne;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getDescp() {
        return descp;
    }

    public void setDescp(String descp) {
        this.descp = descp;
    }

    public Double getDeviceSize() {
        return deviceSize;
    }

    public void setDeviceSize(Double deviceSize) {
        this.deviceSize = deviceSize;
    }

    public Long getDirectoryNumberOne() {
        return directoryNumberOne;
    }

    public void setDirectoryNumberOne(Long directoryNumberOne) {
        this.directoryNumberOne = directoryNumberOne;
    }
}



public class JsonToPojo {
    public static List<Poj>  conver(String data) throws IOException {
        ObjectMapper ob = new ObjectMapper();
       return  ob.readValue(data,new TypeReference<List<Poj>>() { });
    }

    @Test
    public void testConver() throws IOException {
        String data = "[ { \"ADDRESS\" : \"ewrer23214324\", \"DESCP\" : \"LO-3434\", \"DEVICE size\" : \"1.01091E+11\", \"DIRECTORY NUMBER 1\" : \"+34343\" } ]";

        List<Poj> list = JsonToPojo.conver(data);
        for (Poj p:list){
            System.out.println(p.getAddress()+":"+p.getDescp()+":"+p.getDeviceSize()+":"+p.getDirectoryNumberOne());
        }
    }
}
absurd
  • 16
  • 1
  • thanks absurd ,one more question my json data is not fixed it will be keep on changing with different properties ,so i need to maintain everything in one pojo class when ever i get new jsonresponse is it possible to do this? – sharan Sep 19 '16 at 06:28