Coverage Report - com.damnhandy.uri.template.jackson.datatype.UriTemplateDeserializer
 
Classes in this File Line Coverage Branch Coverage Complexity
UriTemplateDeserializer
100%
5/5
N/A
4
 
 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  
  * A {@link JsonDeserializer} that deserializes a string into a {@link UriTemplate}.
 19  
  * 
 20  
  * @author <a href="ryan@damnhandy.com">Ryan J. McDonough</a>
 21  
  * @see JsonDeserializer
 22  
  * @since 2.0
 23  
  * @version $Revision: 1.1 $
 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  
 }