REF: Ignore non existing fields #789

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+17 −2
Split
@@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.client.internal.rest;
+import com.thoughtworks.xstream.mapper.MapperWrapper;
import org.sonatype.nexus.client.internal.msg.ErrorMessage;
import org.sonatype.nexus.client.internal.msg.ErrorResponse;
import org.sonatype.nexus.rest.model.XStreamConfiguratorLightweight;
@@ -33,7 +34,21 @@
*/
public XStream createForXml()
{
- final XStream xstream = new XStream( new LookAheadXppDriver() );
+ final XStream xstream = new XStream(new LookAheadXppDriver())
@cstamas

cstamas Mar 27, 2013

Contributor

Unsure we want to go this path. This snippet flows on the net for very long time, and is part of XStream acceptance tests, but it has drawbacks too.

Joerg describes on XStream user list the drawbacks on this approach (makes impossible use of implicit collections with XStream for example).
See related issues:
http://jira.codehaus.org/browse/XSTR-30
http://jira.codehaus.org/browse/XSTR-691

I'm rather to go with "compatible changes" on DTOs, as described in XStream FAQ. If not possible, introduce new resource with new DTOs instead of reworking old ones (especially if DTO use is shared across multiple resources).

@jdillon

jdillon Mar 27, 2013

Contributor

/me shrugs

We need to do something... we can't simply collect transient deprecated fields for years, nor can we create new resources each time a feature change requires model changes.

+ {
+ // Ignore fields which are present in the payload but not on target class
+ @Override
+ protected MapperWrapper wrapMapper(final MapperWrapper next) {
+ return new MapperWrapper(next)
+ {
+ @Override
+ public boolean shouldSerializeMember(final Class definedIn, final String fieldName) {
+ return definedIn != Object.class && super.shouldSerializeMember(definedIn, fieldName);
+ }
+ };
+ }
+ };
+
xstream.setMode( XStream.NO_REFERENCES );
xstream.autodetectAnnotations( false );
return xstream;
@@ -104,7 +104,7 @@ NX.define('Nexus.util.IconContainer', {
* Reference to installed stylesheet.
*
* @private
- * @type {Stylesheet}
+ * @type {CSSStyleSheet}
*/
stylesheet: undefined,