File tree 3 files changed +47
-5
lines changed
main/java/com/fasterxml/jackson/dataformat/xml
test/java/com/fasterxml/jackson/dataformat/xml/ser
3 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ Project: jackson-dataformat-xml
16
16
`XmlMapper.createParser(XMLStreamReader)` overloads
17
17
#634 : Support use of xsi:type for polymorphic deserialization
18
18
(FromXmlParser.Feature.AUTO_DETECT_XSI_TYPE)
19
+ #637 : `JacksonXmlAnnotationIntrospector.findNamespace()` should
20
+ properly merge namespace information
19
21
* Upgrade Woodstox to 6.6.0 ( latest at the time)
20
22
21
23
2.16.1 (24 -Dec-2023 )
Original file line number Diff line number Diff line change @@ -117,16 +117,27 @@ public PropertyName findRootName(AnnotatedClass ac)
117
117
@ Override
118
118
public String findNamespace (MapperConfig <?> config , Annotated ann )
119
119
{
120
- JacksonXmlProperty prop = _findAnnotation (ann , JacksonXmlProperty .class );
121
- if (prop != null ) {
122
- return prop .namespace ();
120
+ String ns1 = null ;
121
+ JacksonXmlProperty xmlProp = _findAnnotation (ann , JacksonXmlProperty .class );
122
+ if (xmlProp != null ) {
123
+ ns1 = xmlProp .namespace ();
123
124
}
124
125
// 14-Nov-2020, tatu: 2.12 adds namespace for this too
125
126
JsonProperty jprop = _findAnnotation (ann , JsonProperty .class );
127
+ String ns2 = null ;
126
128
if (jprop != null ) {
127
- return jprop .namespace ();
129
+ ns2 = jprop .namespace ();
128
130
}
129
- return null ;
131
+ if (ns1 == null ) {
132
+ return ns2 ;
133
+ }
134
+ if (ns2 == null ) {
135
+ return ns2 ;
136
+ }
137
+ if (ns1 .isEmpty ()) {
138
+ return ns2 ;
139
+ }
140
+ return ns1 ;
130
141
}
131
142
132
143
/**
Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .dataformat .xml .ser ;
2
+
3
+ import com .fasterxml .jackson .annotation .JsonProperty ;
4
+ import com .fasterxml .jackson .dataformat .xml .XmlMapper ;
5
+ import com .fasterxml .jackson .dataformat .xml .XmlTestBase ;
6
+ import com .fasterxml .jackson .dataformat .xml .annotation .JacksonXmlProperty ;
7
+
8
+ // [dataformat-xml#637]
9
+ public class SerializationNameMergingTest extends XmlTestBase
10
+ {
11
+ // [dataformat-xml#637]
12
+ static class NamesBean {
13
+ // XML annotations have precedence over default/standard/json ones
14
+ // but local name, namespace should be merged
15
+ @ JsonProperty (value ="value" , namespace ="uri:ns1" )
16
+ @ JacksonXmlProperty (isAttribute =true )
17
+ public int valueDefault = 42 ;
18
+ }
19
+
20
+ private final XmlMapper MAPPER = newMapper ();
21
+
22
+
23
+ // [dataformat-xml#637]
24
+ public void testNamespaceMerging637 () throws Exception
25
+ {
26
+ assertEquals (a2q ("<NamesBean xmlns:wstxns1='uri:ns1' wstxns1:value='42'/>" ),
27
+ MAPPER .writeValueAsString (new NamesBean ()));
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments