1package net.sghill.example;
2
3import net.sghill.example.User;
4import org.codehaus.jackson.JsonNode;
5import org.codehaus.jackson.JsonParser;
6import org.codehaus.jackson.ObjectCodec;
7import org.codehaus.jackson.map.DeserializationContext;
8import org.codehaus.jackson.map.JsonDeserializer;
9
10import java.io.IOException;
11
12public class UserDeserializer extends JsonDeserializer<User> {
13
14 @Override
15 public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
16 ObjectCodec oc = jsonParser.getCodec();
17 JsonNode node = oc.readTree(jsonParser);
18 return new User(null, node.get("username").getTextValue(), node.get("password").getTextValue());
19 }
20}