SimpleXML: ConstructorException - PullRequest
       17

SimpleXML: ConstructorException

0 голосов
/ 26 июня 2018

Я пытаюсь разобрать некоторые каналы RSS 2.0, подобные этой: https://audioboom.com/channels/4682117.rss

Моя модель выглядит так

Rss Class (файл Java, Котлин также доставлял мне неприятности)

@Root(name = "rss", strict = false)
@Namespace(prefix = "itunes", reference = "http://www.itunes.com/dtds/podcast-1.0.dtd")
public class RSSFeed {

    @Element(name = "title", required = false)
    @Path("channel")
    public String channelTitle = null;

    @Element(name = "description", required = false)
    @Path("channel")
    public String description = null;

    @Element(name = "url", required = false)
    @Path("channel/image")
    String imageUrl = null;

    @ElementList(name = "item", inline = true, required = false)
    @Path("channel")
    public List<Article> articleList = null;
}

Класс предметов (файл Kotlin)

@Root(name = "item", strict = false)
@Namespace(prefix = "itunes", reference = "http://www.itunes.com/dtds/podcast-1.0.dtd")
class Article{

    @set:Path("title")
    @get:Path("title")
    @set:Text(required = false)
    @get:Text(required = false)
    var title: String? = null

    @set:Element(name = "link", required = false)
    @get:Element(name = "link", required = false)
    var url: String? = null

    @set:Element(name = "enclosure", required = false)
    @get:Element(name = "enclosure", required = false)
    var enclosure: Enclosure? = null

    @set:Element(name = "guid", required = false, data = true)
    @get:Element(name = "guid", required = false, data = true)
    var id: String? = null

    @set:Namespace(reference = "http://www.itunes.com/dtds/podcast-1.0.dtd")
    @get:Namespace(reference = "http://www.itunes.com/dtds/podcast-1.0.dtd")
    @set:Element(name = "image", required = false)
    @get:Element(name = "image", required = false)
    var image: Image? = null

    @set:Namespace(reference = "http://www.itunes.com/dtds/podcast-1.0.dtd")
    @get:Namespace(reference = "http://www.itunes.com/dtds/podcast-1.0.dtd")
    @set:Element(name = "duration", required = false)
    @get:Element(name = "duration", required = false)
    var duration: String? = null

    fun getEpisodeUrl(): String? = enclosure?.url ?: url
}

С тех пор, как я включил Progaurd. Я начал получать эту ошибку:

java.lang.RuntimeException: org.simpleframework.xml.core.ConstructorException: конструктор по умолчанию не может принимать только для чтения @ org.simpleframework.xml.Element (data = false, имя = длительность, обязательный = ложь, тип = пустота) для метода «длительность» в класс com.myapp.model.rss.Article

1 Ответ

0 голосов
/ 17 июля 2018

Я получил правильную конфигурацию progaurd от здесь

# SimpleXML
# Save the obfuscation mapping to a file, so we can de-obfuscate any stack
# traces later on. Keep a fixed source file attribute and all line number
# tables to get line numbers in the stack traces.
# You can comment this out if you're not interested in stack traces.

-printmapping out.map
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod

# Preserve all annotations.

-keepattributes *Annotation*

# Add optimizations

-allowaccessmodification
-optimizationpasses 3

# Preserve all public classes, and their public and protected fields and
# methods.

-keep public class * {
    public protected *;
}

# Preserve all .class method names.

-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

# Preserve all native method names and the names of their classes.

-keepclasseswithmembernames class * {
    native <methods>;
}

# Preserve the special static methods that are required in all enumeration
# classes.

-keepclassmembers class * extends java.lang.Enum {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
# You can comment this out if your library doesn't use serialization.
# If your code contains serializable classes that have to be backward
# compatible, please refer to the manual.

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Your library may contain more items that need to be preserved;
# typically classes that are dynamically created using Class.forName:

-keep interface org.simpleframework.xml.core.Label {
   public *;
}
-keep class * implements org.simpleframework.xml.core.Label {
   public *;
}
-keep interface org.simpleframework.xml.core.Parameter {
   public *;
}
-keep class * implements org.simpleframework.xml.core.Parameter {
   public *;
}
-keep interface org.simpleframework.xml.core.Extractor {
   public *;
}
-keep class * implements org.simpleframework.xml.core.Extractor {
   public *;
}

-dontwarn com.bea.xml.stream.**
-dontwarn org.simpleframework.xml.stream.**
-keep class org.simpleframework.xml.**{ *; }
-keepclassmembers,allowobfuscation class * {
    @org.simpleframework.xml.* <fields>;
    @org.simpleframework.xml.* <init>(...);
}
...