1- package tools .jackson .databind .tofix ;
1+ package tools .jackson .databind .node ;
22
33import java .util .ArrayList ;
44import java .util .Iterator ;
1313import tools .jackson .databind .deser .std .DelegatingDeserializer ;
1414import tools .jackson .databind .json .JsonMapper ;
1515import tools .jackson .databind .testutil .DatabindTestUtil ;
16- import tools .jackson .databind .testutil .failure .JacksonTestFailureExpected ;
1716import tools .jackson .databind .type .CollectionLikeType ;
1817
1918
2019import static org .junit .jupiter .api .Assertions .assertSame ;
2120
22- // 30-Mar-2024, tatu: For some reason fails for 3.0 after conversion
23- // to JUnit5. Should fix.
21+ /**
22+ * Test for ensuring that parent references are correctly set during
23+ * deserialization when using custom deserializers with token stream context.
24+ */
2425public class NodeContext2049Test extends DatabindTestUtil
2526{
2627 public interface HasParent {
@@ -131,7 +132,9 @@ public ValueDeserializer<?> createContextual(DeserializationContext ctxt, BeanPr
131132 CollectionLikeType collectionType = ctxt .getTypeFactory ().constructCollectionLikeType (propertyType .getRawClass (),
132133 contentType );
133134 ValueInstantiator instantiator = new ListValueInstantiator ();
134- retValue = new CollectionDeserializer (collectionType , objectDeserializer , null , instantiator );
135+ CollectionDeserializer collDeser = new CollectionDeserializer (collectionType , objectDeserializer , null , instantiator );
136+ // Need to make the CollectionDeserializer contextual
137+ retValue = collDeser .createContextual (ctxt , property );
135138 } else {
136139 retValue = objectDeserializer ;
137140 }
@@ -140,21 +143,17 @@ public ValueDeserializer<?> createContextual(DeserializationContext ctxt, BeanPr
140143
141144 @ Override
142145 public Object deserialize (JsonParser p , DeserializationContext ctxt ) throws JacksonException {
143- // TODO Auto-generated method stub
144- return null ;
146+ throw new UnsupportedOperationException ();
145147 }
146-
147- }
148+ }
148149
149150 /*
150151 /**********************************************************************
151152 /* Test methods
152153 /**********************************************************************
153154 */
154155
155- private ObjectMapper objectMapper ;
156- {
157- objectMapper = JsonMapper .builder ()
156+ private ObjectMapper objectMapper = JsonMapper .builder ()
158157 .addModule (new tools .jackson .databind .JacksonModule () {
159158 @ Override
160159 public String getModuleName () {
@@ -170,7 +169,6 @@ public void setupModule(SetupContext context) {
170169 }
171170 })
172171 .build ();
173- }
174172
175173 final static String JSON = "{\n " +
176174 " \" children\" : [\n " +
@@ -186,7 +184,6 @@ public void setupModule(SetupContext context) {
186184 " }\n " +
187185 "}" ;
188186
189- @ JacksonTestFailureExpected
190187 @ Test
191188 public void testReadNoBuffering () throws Exception {
192189 Parent obj = objectMapper .readerFor (Parent .class ).readValue (JSON );
@@ -196,7 +193,6 @@ public void testReadNoBuffering() throws Exception {
196193 }
197194 }
198195
199- @ JacksonTestFailureExpected
200196 @ Test
201197 public void testReadFromTree () throws Exception {
202198 JsonNode tree = objectMapper .readTree (JSON );
0 commit comments