Announcement Announcement Module
Collapse
No announcement yet.
Spring android JsonMappingException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring android JsonMappingException

    Hi all

    I started using the android rest template and i got a failure i dont understand.

    Code:
    RestTemplate tmpl = new RestTemplate();
            tmpl.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
            List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
            messageConverters.add(new MappingJacksonHttpMessageConverter());
            tmpl.setMessageConverters(messageConverters);
            Task[] tr = tmpl.getForObject("http://10.1.201.167:3001/todo", Task[].class);
    There i try to get these json objects into my Task array.

    This class looks like this:
    Code:
    @JsonIgnoreProperties(ignoreUnknown = true)
    public class Task  {
    
    	private String _id;
    	private String title;
    	private String description;
    	private Date createdAt;
    
    	public Task() {
    		super();
    	}
    	
    	public Task(JsonParser parser, DeserializationContext ctx) {
    		super();
    	}
    	
    	public Task(String str, String a, String b, String c){
    		super();
    	}
    	public Task(String id, String title, String description, Date createdAt){
    		super();
    	}
    	@JsonProperty("_id")
    	public String getId() {
    		return _id;
    	}
    	@JsonProperty("_id")
    	public void setId(String id) {
    		_id = id;
    	}
    	@JsonProperty("created_at")
    	public Date getCreatedAt() {
    		return createdAt;
    	}
    	@JsonProperty("created_at")
    	public void setCreatedAt(Date createdAt) {
    		this.createdAt = createdAt;
    	}
    	@JsonProperty("title")
    	public String getTitle() {
    		return title;
    	}
    	@JsonProperty("title")
    	public void setTitle(String title) {
    		this.title = title;
    	}
    	@JsonProperty("description")
    	public String getDescription() {
    		return description;
    	}
    	@JsonProperty("description")
    	public void setDescription(String description) {
    		this.description = description;
    	}
    }
    I always get a JsonMappingException: Can not construct instance of ch.company.android.Task, problem: no suitable creator method found to deserialize from Json String

    What am i doing wrong?

    Oh and none of these Constructors is called.
    Last edited by MaxGfeller; Feb 17th, 2011, 03:50 AM.

  • #2
    Hallo, schön dich zu treffen! Ich zum ersten Mal diese Art von Forum, in der Hoffnung, zu einem späteren Zeitpunkt werden Ihre Führer! ! ! Vielen Dank! ! ! ! !

    Comment

    Working...
    X