1
1
package com .fasterxml .jackson .dataformat .smile ;
2
2
3
+ import java .io .*;
3
4
import java .util .*;
4
5
5
6
import com .fasterxml .jackson .databind .*;
@@ -121,7 +122,8 @@ public void testRoundTrip() throws Exception
121
122
ObjectMapper mapper = smileMapper (false );
122
123
123
124
byte [] smile1 = mapper .writeValueAsBytes (citm );
124
- Citm citm2 = mapper .readValue (smile1 , Citm .class );
125
+ // IMPORTANT: use InputStream so boundary conditions are actually checked
126
+ Citm citm2 = mapper .readValue (new ByteArrayInputStream (smile1 ), Citm .class );
125
127
byte [] smile2 = mapper .writeValueAsBytes (citm2 );
126
128
127
129
assertEquals (smile1 .length , smile2 .length );
@@ -138,4 +140,34 @@ public void testRoundTrip() throws Exception
138
140
assertEquals (citm .topicSubTopics .size (), citm2 .topicSubTopics .size ());
139
141
assertEquals (citm .venueNames .size (), citm2 .venueNames .size ());
140
142
}
143
+
144
+ public void testIssue17BoundaryWithFloat () throws Exception
145
+ {
146
+ _testWithFloats (false );
147
+ _testWithFloats (true );
148
+ }
149
+
150
+ private void _testWithFloats (boolean useHeader ) throws Exception
151
+ {
152
+ double [] data = new double [4096 ];
153
+ for (int i = 0 ; i < data .length ; ++i ) {
154
+ data [i ] = (double ) i ;
155
+ }
156
+ ObjectMapper mapper = smileMapper (useHeader );
157
+ byte [] encoded = mapper .writeValueAsBytes (data );
158
+
159
+ // first, read from byte array; no boundary
160
+ double [] decoded = mapper .readValue (encoded , double [].class );
161
+ assertEquals (data .length , decoded .length );
162
+
163
+ // and then via InputStream
164
+ decoded = mapper .readValue (new ByteArrayInputStream (encoded ), double [].class ); // This fails on 2.4.0
165
+ assertEquals (data .length , decoded .length );
166
+
167
+ for (int i = 0 ; i < data .length ; ++i ) {
168
+ if (data [i ] != decoded [i ]) {
169
+ assertEquals ("Different value at #" +i , data [i ], decoded [i ]);
170
+ }
171
+ }
172
+ }
141
173
}
0 commit comments