• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.util;
2 
3 import com.fasterxml.jackson.databind.JavaType;
4 import com.fasterxml.jackson.databind.type.TypeFactory;
5 
6 /**
7  * Helper interface for things that convert Objects of
8  * one type to another.
9  *<p>
10  * NOTE: implementors are strongly encouraged to extend {@link StdConverter}
11  * instead of directly implementing {@link Converter}, since that can
12  * help with default implementation of typically boiler-plate code.
13  *
14  * @param <IN> Type of values converter takes
15  * @param <OUT> Result type from conversion
16  *
17  * @see com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer
18  * @see com.fasterxml.jackson.databind.deser.std.StdDelegatingDeserializer
19  *
20  * @since 2.1
21  */
22 public interface Converter<IN,OUT>
23 {
24     /**
25      * Main conversion method.
26      */
convert(IN value)27     public OUT convert(IN value);
28 
29     /**
30      * Method that can be used to find out actual input (source) type; this
31      * usually can be determined from type parameters, but may need
32      * to be implemented differently from programmatically defined
33      * converters (which cannot change static type parameter bindings).
34      *
35      * @since 2.2
36      */
getInputType(TypeFactory typeFactory)37     public JavaType getInputType(TypeFactory typeFactory);
38 
39     /**
40      * Method that can be used to find out actual output (target) type; this
41      * usually can be determined from type parameters, but may need
42      * to be implemented differently from programmatically defined
43      * converters (which cannot change static type parameter bindings).
44      *
45      * @since 2.2
46      */
getOutputType(TypeFactory typeFactory)47     public JavaType getOutputType(TypeFactory typeFactory);
48 
49     /*
50     /**********************************************************
51     /* Helper class(es)
52     /**********************************************************
53      */
54 
55     /**
56      * This marker class is only to be used with annotations, to
57      * indicate that <b>no converter is to be used</b>.
58      *<p>
59      * Specifically, this class is to be used as the marker for
60      * annotation {@link com.fasterxml.jackson.databind.annotation.JsonSerialize},
61      * property <code>converter</code> (and related)
62      *
63      * @since 2.2
64      */
65     public abstract static class None
66         implements Converter<Object,Object> { }
67 }
68