El programa Java Json no muestra ningún resultado.
Lo que quiero hacer es, cuando navego a:
http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=[your_api_key◆&q=Toy+Story+3&page_limit=1
Devuelve una respuesta JSON. Quiero convertirlo en objeto Java. Estoy usando la biblioteca de Jackson. Esta es mi clase de datos:
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown=true)
public class Aman
{
public static class Title
{
private String title;
public String getTitle(){ return title; }
public String setTitle(String s){ return title = s; }
}
private int id;
private int year;
private int total;
public void SetId(int i){ id = i; }
public void SetYear(int y){ year = y; }
public void SetTotal(int t){ total =t; }
public int GetId()
{
return id;
}
public int GetYear()
{
return year;
}
public int GetTotal()
{
return total;
}
@Override
public String toString()
{
return "Movies[total=" +total + "id=" + id + "year=" + year + "]";
}
}
y mi clase de mapeador:
import java.io.File;
import java.io.IOException;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import java.net.*;
public class Movie
{
public static void main(String[] args) throws MalformedURLException, URISyntaxException, IOException {
Aman a = new Aman();
ObjectMapper mapper = new ObjectMapper();
try
{
URL RT = new URL("http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=gzscv4f8zqse75w94mmp37zz&q=Toy+Story+3&page_limit=1").toURI().toURL();
a = mapper.readValue(RT, Aman.class);
}catch(MalformedURLException u)
{
u.printStackTrace();
}catch(URISyntaxException s)
{
s.printStackTrace();
}catch(IOException i)
{
i.printStackTrace();
}
}
}
No me muestra ninguna salida en absoluto. ¿Estoy haciendo algo mal?