After a lot of trial and error I got it working. Take a look at my results...
Example:
Execution of the getForObjectMethod
Code:
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(new CommonsClientHttpRequestFactory());
//fill the rest template
MyObjectResponse objectResponse = restTemplate.getForObject("http://someurl", MyObjectResponse.class);
The wrapper file
Code:
public class MyObjectResponse {
private MyObject myObject;
public MyObject getMyObject() {
return myObject;
}
public void setMyObject( MyObject myObject ) {
this.myObject = myObject;
}
}
class "myObject"
Code:
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true) //must be there all times most likely
public class MyObject {
/*
* Attributes
*/
@JsonProperty //this annotation is also necessary
private String title;
@JsonProperty
private String id, created_at, updated_at;
@JsonProperty
private Image[] images;
/*
* All Attributes have getters and setters (generated by Eclipse - right click - source - generate getters and setters)
*/
The nested image class
Code:
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Image {
@JsonProperty
private Integer width, height;
@JsonProperty
private String url, type, size;
public Integer getWidth() {
return width;
}
public void setWidth( Integer width ) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight( Integer height ) {
this.height = height;
}
public String getUrl() {
return url;
}
public void setUrl( String url ) {
this.url = url;
}
public String getType() {
return type;
}
public void setType( String type ) {
this.type = type;
}
public String getSize() {
return size;
}
public void setSize( String size ) {
this.size = size;
}
}