JSON schema/Example to model converter
http://www.jsonschema2pojo.org/
This supports Jackson and Google gson JSON libraries.
JSON Viewer
http://jsonviewer.stack.hu/
Example: for my project JSON example
{
"projectName":"TestProject",
"properties": {
"createdBy": "Kondal Kolipaka",
"createdTime": "21-01-2013",
"lastModifiedTime":"21-02-2013"
}
}
Generated Model for above Project JSON example:
package com.kk;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
(JsonInclude.Include.NON_NULL)
("com.googlecode.jsonschema2pojo")
({
"projectName",
"properties"
})
public class Project {
("projectName")
private String projectName;
("properties")
private Properties properties;
private Map<String, Object> additionalProperties = newHashMap<String, Object>();
("projectName")
public String getProjectName() {
return projectName;
}
("projectName")
public void setProjectName(String projectName) {
this.projectName = projectName;
}
("properties")
public Properties getProperties() {
return properties;
}
("properties")
public void setProperties(Properties properties) {
this.properties = properties;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperties(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
-----------------------------------com.kk.Properties.java-----------------------------------
package com.kk;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
(JsonInclude.Include.NON_NULL)
("com.googlecode.jsonschema2pojo")
({
"createdBy",
"createdTime",
"lastModifiedTime"
})
public class Properties {
("createdBy")
private String createdBy;
("createdTime")
private String createdTime;
("lastModifiedTime")
private String lastModifiedTime;
private Map<String, Object> additionalProperties = newHashMap<String, Object>();
("createdBy")
public String getCreatedBy() {
return createdBy;
}
("createdBy")
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
("createdTime")
public String getCreatedTime() {
return createdTime;
}
("createdTime")
public void setCreatedTime(String createdTime) {
this.createdTime = createdTime;
}
("lastModifiedTime")
public String getLastModifiedTime() {
return lastModifiedTime;
}
("lastModifiedTime")
public void setLastModifiedTime(String lastModifiedTime) {
this.lastModifiedTime = lastModifiedTime;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperties(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
As we can see it also generates getAdditionalProperties(), this would be very much useful later point of time if we wanted to send some additional information without really modifying the existing structure.