Announcement Announcement Module
Collapse
No announcement yet.
RIAK: Mapping JSON response to an Object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RIAK: Mapping JSON response to an Object

    Has anyone tried to map a response to an object in Riak? Is there some extra-magic that needs to be configured?

    My bean:
    Code:
    public class User implements Serializable {
        private long id;
        private String firstName;
        private String lastName;
    
        @JsonCreator
        public User(@JsonProperty final long id, @JsonProperty final String firstName, @JsonProperty final String lastName) {
            setId(id);
            setFirstName(firstName);
            setLastName(lastName);
        }
    
        public long getId() {
            return id;
        }
    
        public void setId(long id) {
            this.id = id;
        }
    
        public String getFirstName() {
            return firstName;
        }
    
        public void setFirstName(final String firstName) {
            this.firstName = firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public void setLastName(final String lastName) {
            this.lastName = lastName;
        }
    }
    Works fine:
    Code:
    final User user = new User(ID, FNAME, LNAME);
    riakTemplate.set(BUCKET, ID, user);
    
    if(riakTemplate.containsKey(BUCKET, ID))
         System.out.println("found it.");
    Does NOT work:
    Code:
    final User user = new User(ID, FNAME, LNAME);
    riakTemplate.set(BUCKET, ID, user);
    
    User myUser = riakTemplate.getAsType(BUCKET, ID, User.class);
    This last one results in the User object being null. Looking into the debug logs, I can see this:

    Code:
    1545 [main] DEBUG org.springframework.data.keyvalue.riak.core.RiakTemplate  - RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [com.marvlush.riak.domain.User] and content type [application/json]
    Do I have to tell the RiakTemplate that its ok to convert application/json responses to my User object? Which is odd, because it already knows how to convert from my User object type to JSON, so wouldn't it stand to reason it should already know how go the other direction?

    Thanks in advance.

    /m
Working...
X