| 230 | | TileLayer tileLayer = (WMSLayer) xs.fromXML(xmlText); |
| | 237 | TileLayer tileLayer = null; |
| | 238 | if(entity.getMediaType().equals(MediaType.APPLICATION_XML)){ |
| | 239 | tileLayer = (WMSLayer) xs.fromXML(xmlText); |
| | 240 | } |
| | 241 | |
| | 242 | /** |
| | 243 | * deserializing a json string is more complicated. XStream does not natively |
| | 244 | * support it. Rather it uses a JettisonMappedXmlDriver to convert to intermediate xml |
| | 245 | * and then deserializes that into the desired object. At this time, there is a known issue |
| | 246 | * with the Jettison driver involving elements that come after an array in the json string. |
| | 247 | * |
| | 248 | * http://jira.codehaus.org/browse/JETTISON-48 |
| | 249 | * |
| | 250 | * The code below is a hack: it treats the json string as text, then converts it to the intermediate |
| | 251 | * xml and then deserializes that into the tileLayer object. |
| | 252 | * |
| | 253 | * |
| | 254 | */ |
| | 255 | else if(entity.getMediaType().equals(MediaType.APPLICATION_JSON)){ |
| | 256 | HierarchicalStreamDriver driver = new JettisonMappedXmlDriver(); |
| | 257 | StringReader reader = new StringReader(xmlText); |
| | 258 | HierarchicalStreamReader hsr = driver.createReader(reader); |
| | 259 | StringWriter writer = new StringWriter(); |
| | 260 | new HierarchicalStreamCopier().copy(hsr, new PrettyPrintWriter(writer)); |
| | 261 | writer.close(); |
| | 262 | |
| | 263 | XStream x = new XStream(new DomDriver()); |
| | 264 | x.alias("wmslayer", WMSLayer.class); |
| | 265 | x.aliasField("layer-name", TileLayer.class, "name"); |
| | 266 | x.alias("grid", Grid.class); |
| | 267 | |
| | 268 | |
| | 269 | tileLayer = (WMSLayer) x.fromXML(writer.toString()); |
| | 270 | } |
| | 271 | |