|
7 | 7 | import javax.xml.namespace.QName;
|
8 | 8 |
|
9 | 9 | import com.fasterxml.jackson.core.*;
|
| 10 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 11 | + |
10 | 12 | import com.fasterxml.jackson.databind.*;
|
11 | 13 | import com.fasterxml.jackson.databind.deser.Deserializers;
|
12 | 14 | import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer;
|
@@ -40,7 +42,10 @@ public JsonDeserializer<?> findBeanDeserializer(JavaType type,
|
40 | 42 | {
|
41 | 43 | Class<?> raw = type.getRawClass();
|
42 | 44 | if (raw == QName.class) {
|
43 |
| - return new Std(raw, TYPE_QNAME); |
| 45 | + if (config == null || config.isEnabled(DeserializationFeature.READ_QNAMES_USING_VALUE_OF)) { |
| 46 | + return new Std(raw, TYPE_QNAME); |
| 47 | + } |
| 48 | + return new QNameObjectDeserializer(); |
44 | 49 | }
|
45 | 50 | if (raw == XMLGregorianCalendar.class) {
|
46 | 51 | return new Std(raw, TYPE_G_CALENDAR);
|
@@ -149,4 +154,27 @@ protected XMLGregorianCalendar _gregorianFromDate(DeserializationContext ctxt,
|
149 | 154 | return _dataTypeFactory.newXMLGregorianCalendar(calendar);
|
150 | 155 | }
|
151 | 156 | }
|
| 157 | + |
| 158 | + private class QNameObjectDeserializer extends JsonDeserializer<QName> { |
| 159 | + private static final long serialVersionUID = 1L; |
| 160 | + public static final TypeReference<Map<String, String>> STRING_MAP_TYPE_REFERENCE = new TypeReference<>() {}; |
| 161 | + |
| 162 | + @Override |
| 163 | + public QName deserialize(final JsonParser p, final DeserializationContext ctxt) |
| 164 | + throws IOException |
| 165 | + { |
| 166 | + Map<String, String> map; |
| 167 | + try { |
| 168 | + map = p.readValueAs(STRING_MAP_TYPE_REFERENCE); |
| 169 | + } catch (IOException e) { |
| 170 | + throw new JsonMappingException(p, "Unable to parse the QName as an object.", e); |
| 171 | + } |
| 172 | + |
| 173 | + return new QName( |
| 174 | + map.getOrDefault("namespaceURI", ""), |
| 175 | + map.getOrDefault("localPart", ""), |
| 176 | + map.getOrDefault("prefix", "") |
| 177 | + ); |
| 178 | + } |
| 179 | + } |
152 | 180 | }
|
0 commit comments