1
- package com .fasterxml .jackson .databind .failing ;
1
+ package com .fasterxml .jackson .databind .records ;
2
+
3
+ import java .util .*;
4
+
5
+ import org .junit .jupiter .api .Test ;
2
6
3
7
import com .fasterxml .jackson .annotation .JsonCreator ;
4
8
import com .fasterxml .jackson .annotation .JsonProperty ;
5
9
import com .fasterxml .jackson .databind .ObjectMapper ;
6
10
import com .fasterxml .jackson .databind .json .JsonMapper ;
7
- import com .fasterxml .jackson .databind .records .Jdk8ConstructorParameterNameAnnotationIntrospector ;
8
- import org .junit .jupiter .api .Test ;
9
11
10
12
import static org .junit .jupiter .api .Assertions .assertEquals ;
11
- import static org .junit .jupiter .api .Assertions .assertTrue ;
12
13
13
14
// [databind#4452] : JsonProperty not serializing field names properly on JsonCreator in record #4452
14
15
class RecordCreatorSerialization4452Test {
@@ -37,32 +38,22 @@ public CreatorTestObject(
37
38
.annotationIntrospector (new Jdk8ConstructorParameterNameAnnotationIntrospector ())
38
39
.build ();
39
40
40
- // supposed to pass, and yes it does
41
41
@ Test
42
- public void testPlain ()
43
- throws Exception
42
+ public void testPlain () throws Exception
44
43
{
45
44
String result = OBJECT_MAPPER .writeValueAsString (new PlainTestObject ("test" , 1 ));
46
45
assertEquals ("{\" strField\" :\" test\" ,\" intField\" :1}" , result );
47
46
}
48
47
49
- // Should pass but doesn't
50
- // It did pass in 2.15 or earlier versions, but it fails in 2.16 or later
51
48
@ Test
52
- public void testWithCreator ()
53
- throws Exception
49
+ public void testWithCreator () throws Exception
54
50
{
55
- String result = OBJECT_MAPPER
51
+ String json = OBJECT_MAPPER
56
52
.writeValueAsString (new CreatorTestObject ("test" , 2 , 1 ));
53
+ //System.err.println("JSON: "+json);
57
54
58
- /*
59
- Serializes to (using System.err.println("JSON: "+result); )
60
-
61
- {"testFieldName":"test","testOtherField":3}
62
-
63
- */
64
- assertTrue (result .contains ("intField" ));
65
- assertTrue (result .contains ("strField" ));
55
+ @ SuppressWarnings ("unchecked" )
56
+ Map <String , Object > asMap = (Map <String , Object >) OBJECT_MAPPER .readValue (json , Map .class );
57
+ assertEquals (new HashSet <>(Arrays .asList ("intField" , "strField" )), asMap .keySet ());
66
58
}
67
-
68
- }
59
+ }
0 commit comments