Skip to content

Commit 309bb14

Browse files
author
Alain Gilbert
committed
Fix Infinite recursion (StackOverflowError) when serializing a SOAP object.
1 parent 3470803 commit 309bb14

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/main/java/com/fasterxml/jackson/databind/ext/OptionalHandlerFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType typ
4545
String className = rawType.getName();
4646
String factoryName;
4747

48-
if (className.startsWith(PACKAGE_PREFIX_JAVAX_XML)
49-
|| hasSupertypeStartingWith(rawType, PACKAGE_PREFIX_JAVAX_XML)) {
50-
factoryName = SERIALIZERS_FOR_JAVAX_XML;
51-
} else if (doesImplement(rawType, CLASS_NAME_DOM_NODE)) {
48+
if (doesImplement(rawType, CLASS_NAME_DOM_NODE)) {
5249
return (JsonSerializer<?>) instantiate(SERIALIZER_FOR_DOM_NODE);
50+
}
51+
if (className.startsWith(PACKAGE_PREFIX_JAVAX_XML) || hasSupertypeStartingWith(rawType, PACKAGE_PREFIX_JAVAX_XML)) {
52+
factoryName = SERIALIZERS_FOR_JAVAX_XML;
5353
} else {
5454
return null;
5555
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.fasterxml.jackson.databind.ext;
2+
3+
import javax.xml.soap.Detail;
4+
import javax.xml.soap.SOAPException;
5+
import javax.xml.soap.SOAPFactory;
6+
7+
import com.fasterxml.jackson.core.JsonProcessingException;
8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
10+
public class TestSOAP extends com.fasterxml.jackson.databind.BaseMapTest {
11+
12+
public void testSerializeSOAP() throws SOAPException, JsonProcessingException {
13+
ObjectMapper objectMapper = new ObjectMapper();
14+
SOAPFactory fac = SOAPFactory.newInstance();
15+
Detail detailElement = fac.createDetail();
16+
detailElement.setTextContent("test");
17+
String result = objectMapper.writer().writeValueAsString(detailElement);
18+
assertNotNull(result);
19+
}
20+
}

0 commit comments

Comments
 (0)