8
8
9
9
import org .junit .Assert ;
10
10
11
+ import com .fasterxml .jackson .annotation .JsonCreator ;
12
+ import com .fasterxml .jackson .annotation .JsonValue ;
11
13
import com .fasterxml .jackson .core .*;
14
+ import com .fasterxml .jackson .core .type .TypeReference ;
12
15
import com .fasterxml .jackson .databind .JsonNode ;
13
16
import com .fasterxml .jackson .databind .ObjectMapper ;
17
+ import com .fasterxml .jackson .databind .exc .MismatchedInputException ;
14
18
import com .fasterxml .jackson .databind .node .ArrayNode ;
15
19
import com .fasterxml .jackson .dataformat .smile .BaseTestForSmile ;
16
20
import com .fasterxml .jackson .dataformat .smile .SmileFactory ;
@@ -24,12 +28,31 @@ public BytesBean() { }
24
28
public BytesBean (byte [] b ) { bytes = b ; }
25
29
}
26
30
31
+ // [dataformats-binary#1711]
32
+ static class ByteWrapper1711 {
33
+ private final byte [] val ;
34
+
35
+ @ JsonCreator // (mode=JsonCreator.Mode.DELEGATING)
36
+ public ByteWrapper1711 (byte [] val ) {
37
+ this .val = val ;
38
+ }
39
+
40
+ @ JsonValue public byte [] getValue () { return val ;}
41
+ }
42
+
43
+ static class Wrapper <V > {
44
+ public V value ;
45
+
46
+ protected Wrapper () { }
47
+ public Wrapper (V v ) { value = v ; }
48
+ }
49
+
27
50
/*
28
51
/**********************************************************
29
52
/* Test methods
30
53
/**********************************************************
31
54
*/
32
-
55
+
33
56
private final ObjectMapper MAPPER = smileMapper ();
34
57
35
58
public void testBinary () throws IOException
@@ -42,6 +65,29 @@ public void testBinary() throws IOException
42
65
Assert .assertArrayEquals (input , result .bytes );
43
66
}
44
67
68
+ // [dataformats-binary#1711]
69
+ public void testWrappedBinary () throws IOException
70
+ {
71
+ byte [] bytes = {1 , 2 , 3 , 4 , 5 };
72
+ byte [] smile = MAPPER .writeValueAsBytes (new ByteWrapper1711 (bytes ));
73
+ ByteWrapper1711 read = MAPPER .readValue (smile , ByteWrapper1711 .class );
74
+ if (!Arrays .equals (bytes , read .val )) {
75
+ throw new IllegalStateException ("Arrays not equal" );
76
+ }
77
+
78
+ // also, verify exception we get if there's no match...
79
+ smile = MAPPER .writeValueAsBytes (new Wrapper <>(new ByteWrapper1711 (bytes )));
80
+ try {
81
+ Wrapper <?> ob = MAPPER .readValue (smile , new TypeReference <Wrapper <BytesBean >>() { });
82
+ Object val = ob .value ;
83
+ fail ("Should not pass, Wrapper value should be `BytesBean`, got: " +val .getClass ().getName ());
84
+ } catch (MismatchedInputException e ) {
85
+ verifyException (e , "Cannot deserialize value of type" );
86
+ verifyException (e , BytesBean .class .getName ());
87
+ verifyException (e , "incompatible types" );
88
+ }
89
+ }
90
+
45
91
// UUIDs should be written as binary (starting with 2.3)
46
92
public void testUUIDs () throws IOException
47
93
{
0 commit comments