Skip to content

Commit 1c1c1b8

Browse files
authored
Prepping for #5242 (#5248)
1 parent 2ffb3ff commit 1c1c1b8

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/test/java/com/fasterxml/jackson/databind/ser/jdk/UUIDSerializationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.fasterxml.jackson.databind.ser.jdk;
22

3-
import java.io.IOException;
43
import java.util.UUID;
54

65
import org.junit.jupiter.api.Test;
@@ -35,7 +34,7 @@ static class UUIDWrapperBinary {
3534

3635
// Verify that efficient UUID codec won't mess things up:
3736
@Test
38-
public void testBasicUUIDs() throws IOException
37+
public void testBasicUUIDs() throws Exception
3938
{
4039
// first, couple of generated UUIDs:
4140
for (String value : new String[] {
@@ -104,5 +103,4 @@ public void testTreeConversion() throws Exception
104103
Object ob = MAPPER.convertValue(nullUUID, Object.class);
105104
assertEquals(String.class, ob.getClass());
106105
}
107-
108106
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fasterxml.jackson.databind.ser.jdk;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
7+
8+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
/**
12+
* Tests for serialization (and deserialization) of {@code float[]}
13+
* as "packed binary" data, as per [databind#5242].
14+
*/
15+
public class VectorsAsBinarySerTest extends DatabindTestUtil
16+
{
17+
private final static float[] FLOAT_VECTOR = new float[] { 1.0f, 0.5f, -1.25f };
18+
private final static String FLOAT_VECTOR_STR = "[1.0,0.5,-1.25]";
19+
20+
private final static double[] DOUBLE_VECTOR = new double[] { -1.0, 1.5, 0.0125 };
21+
private final static String DOUBLE_VECTOR_STR = "[-1.0,1.5,0.0125]";
22+
23+
private final ObjectMapper MAPPER = sharedMapper();
24+
25+
// // // Float Vector tests
26+
27+
@Test
28+
public void defaultFloatVectorSerialization() throws Exception {
29+
String json = MAPPER.writeValueAsString(FLOAT_VECTOR);
30+
assertEquals(FLOAT_VECTOR_STR, json);
31+
32+
float[] result = MAPPER.readValue(json, float[].class);
33+
assertArrayEquals(FLOAT_VECTOR, result);
34+
}
35+
36+
// // // Double Vector tests
37+
38+
@Test
39+
public void defaultDoubleVectorSerialization() throws Exception {
40+
String json = MAPPER.writeValueAsString(DOUBLE_VECTOR);
41+
assertEquals(DOUBLE_VECTOR_STR, json);
42+
43+
double[] result = MAPPER.readValue(json, double[].class);
44+
assertArrayEquals(DOUBLE_VECTOR, result);
45+
}
46+
}

0 commit comments

Comments
 (0)