gpt4 book ai didi

java - 简单XML : ConstructorException

转载 作者:太空宇宙 更新时间:2023-11-04 10:22:00 25 4
gpt4 key购买 nike

我正在尝试解析一些 RSS 2.0 提要,如下所示: https://audioboom.com/channels/4682117.rss

我的模型看起来像这样

Rss Class(Java文件,Kotlin也给我带来了麻烦)

@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: Default constructor can not accept read only @org.simpleframework.xml.Element(data=false, name=duration, required=false, type=void) on method 'duration' in class com.myapp.model.rss.Article

最佳答案

我从 here 获得了正确的 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>(...);
}

关于java - 简单XML : ConstructorException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51040272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com