Announcement Announcement Module
Collapse
No announcement yet.
RestTemplate with MappingJacksonHttpMessageConverter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RestTemplate with MappingJacksonHttpMessageConverter

    I am trying to get object from json:

    User user = new User();

    RestTemplate restTemplate = new RestTemplate();

    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new MappingJacksonHttpMessageConverter());
    restTemplate.setMessageConverters(messageConverter s);


    user = restTemplate.getForObject( "www.example.com/whereThereIsAUserJson",
    User.class);

    System.out.println(user);


    @JsonIgnoreProperties(ignoreUnknown = false)
    public class User {

    @JsonProperty
    private Date createDateTime;
    @JsonProperty
    private Date updateDateTime;
    @JsonProperty
    private long id;
    @JsonProperty
    private String password;
    @JsonProperty
    private String displayName;
    @JsonProperty
    private String email;
    //getters and setters
    }


    I have an error message: [org.springframework.web.client.RestTemplate ][main ] GET request for "www.example.com/whereThereIsAUserJson" resulted in 406 (Not Acceptable); invoking error handler

    What is missing in this code? Json is visible in the browser.
Working...
X