Private
Public Access
1
0

Migrate to Xstream to prevent too many changes. Still have memory issue, but some flexibility to still find away around it.

This commit is contained in:
Kevin Whitaker
2015-11-20 00:44:21 -05:00
parent a938ef0512
commit 586dcbf8a4
5 changed files with 50 additions and 49 deletions

View File

@@ -29,9 +29,7 @@ dependencies {
compile 'com.squareup.picasso:picasso:2.5.2' //Apache 2.0
compile 'com.github.thorbenprimke:realm-recyclerview:0.9.5' //Apache 2.0
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' //Apache 2.0
compile ('com.squareup.retrofit:converter-simplexml:2.0.0-beta2') {
exclude group: 'xpp3', module: 'xpp3'
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
compile ('com.thoughtworks.xstream:xstream:1.4.7') { //BSD
exclude group: 'xmlpull'
}
}

View File

@@ -1,10 +1,12 @@
package com.magnatune.eyecreate.companionformagnatune.api;
import com.magnatune.eyecreate.companionformagnatune.model.AlbumResponse;
import com.magnatune.eyecreate.companionformagnatune.model.xml.Album;
import com.magnatune.eyecreate.companionformagnatune.model.xml.Track;
import com.squareup.okhttp.ResponseBody;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;
import com.thoughtworks.xstream.io.xml.Xpp3Driver;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
@@ -15,10 +17,15 @@ public class MagnatuneAlbumsConverter implements Converter<ResponseBody,AlbumRes
@Override
public AlbumResponse convert(ResponseBody value) throws IOException {
GZIPInputStream compressedStream = new GZIPInputStream(value.byteStream());
Serializer serializer = new Persister();
XStream parser = new XStream(new Xpp3Driver());
parser.processAnnotations(Album.class);
parser.processAnnotations(Track.class);
parser.processAnnotations(AlbumResponse.class);
parser.registerConverter(new DateConverter("yyyy-MM-dd",new String[]{}));
parser.ignoreUnknownElements();
AlbumResponse conversion = null;
try {
conversion = serializer.read(AlbumResponse.class,compressedStream);
conversion = (AlbumResponse) parser.fromXML(compressedStream);
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -1,16 +1,14 @@
package com.magnatune.eyecreate.companionformagnatune.model;
import com.magnatune.eyecreate.companionformagnatune.model.xml.*;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import java.util.List;
@Root(name="AllAlbums")
@XStreamAlias("AllAlbums")
public class AlbumResponse {
@ElementList(inline=true,type= com.magnatune.eyecreate.companionformagnatune.model.xml.Album.class)
@XStreamImplicit(itemFieldName = "Album")
public List<com.magnatune.eyecreate.companionformagnatune.model.xml.Album> albums;
}

View File

@@ -1,51 +1,50 @@
package com.magnatune.eyecreate.companionformagnatune.model.xml;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import java.util.Date;
import java.util.List;
@Root(name="Album",strict = false)
@XStreamAlias("Album")
public class Album {
@Element
public String artist;
@Element
public String artistdesc;
@Element
public String cover_small;
@Element
public String artistphoto;
@Element
public String albumname;
@Element
public int year;
@Element(required = false)
public String album_notes;
@Element
public String mp3genre;
@Element
public String home;
@Element
public String magnatunegenres;
@Element
public Date launchdate;
@Element
public String albumsku;
@ElementList(inline=true,type=Track.class)
@XStreamImplicit(itemFieldName = "Track")
public List<Track> tracks;
}

View File

@@ -1,49 +1,48 @@
package com.magnatune.eyecreate.companionformagnatune.model.xml;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@Root(name="Track",strict = false)
@XStreamAlias("Track")
public class Track {
@Element
public String artist;
@Element
public String artistbio;
@Element
public String albumname;
@Element
public String trackname;
@Element
public int tracknum;
@Element
public int year;
@Element
public String mp3genre;
@Element
public String magnatunegenres;
@Element
public String license;
@Element
public long seconds;
@Element
public String url;
@Element
public String mp3lofi;
@Element
public String oggurl;
@Element
public String isrc;
}