1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package com.damnhandy.uri.template.jackson.datatype; |
6 | |
|
7 | |
import java.io.IOException; |
8 | |
|
9 | |
import com.damnhandy.uri.template.MalformedUriTemplateException; |
10 | |
import com.damnhandy.uri.template.UriTemplate; |
11 | |
import com.fasterxml.jackson.core.JsonParseException; |
12 | |
import com.fasterxml.jackson.core.JsonParser; |
13 | |
import com.fasterxml.jackson.core.JsonProcessingException; |
14 | |
import com.fasterxml.jackson.databind.DeserializationContext; |
15 | |
import com.fasterxml.jackson.databind.JsonDeserializer; |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | 12 | public class UriTemplateDeserializer extends JsonDeserializer<UriTemplate> |
26 | |
{ |
27 | |
|
28 | |
@Override |
29 | |
public UriTemplate deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, |
30 | |
JsonProcessingException |
31 | |
{ |
32 | |
|
33 | 8 | String value = parser.getText(); |
34 | |
try |
35 | |
{ |
36 | 8 | return UriTemplate.fromTemplate(value); |
37 | |
} |
38 | 2 | catch (MalformedUriTemplateException e) |
39 | |
{ |
40 | 2 | throw new JsonParseException("Error parsing the URI Template", parser.getCurrentLocation(), e); |
41 | |
} |
42 | |
} |
43 | |
|
44 | |
} |