android – ProGuard – org.codehaus.jackson.map.JsonMappingException:没有为类型找到合适的构造函数

前端之家收集整理的这篇文章主要介绍了android – ProGuard – org.codehaus.jackson.map.JsonMappingException:没有为类型找到合适的构造函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个基于Android的应用程序,它使用Rest服务连接到Google App Engine,该应用程序完美运行,直到它在发布之前通过ProGuard进行模糊处理.

运行混淆应用程序时LogCat中报告的错误是:

  1. Unable to convert a [application/json,UTF-8] representation into an object of
  2. class com.enterprisemk.android.bcw.bincollection.WasteCollectionAreasContainer
  3. org.codehaus.jackson.map.JsonMappingException: No suitable constructor found
  4. for type [simple type,class
  5. com.enterprisemk.android.bcw.bincollection.WasteCollectionAreasContainer]:
  6. can not instantiate from JSON object (need to add/enable type information?)

我在proguard-project.txt文件中有以下内容

  1. -keepattributes *Annotation*,EnclosingMethod
  2. -keep public class org.w3c.** {public private protected *;}
  3. -dontwarn org.w3c.**
  4. -keep public class org.joda.time.** {public private protected *;}
  5. -dontwarn org.joda.time.**
  6. -keep public class org.restlet.** { *; }
  7. -dontwarn org.restlet.**
  8. -keep public class org.codehaus.** { *; }
  9. -dontwarn org.codehaus.**
  10. -keepattributes Signature
  11. -keepnames class com.fasterxml.jackson.** { *; }
  12. -dontwarn com.fasterxml.jackson.databind.**

而我的班级错误指的是:

  1. public class WasteCollectionAreasContainer {
  2. public List

要在通过ProGuard进行模糊处理之前重申该应用程序可以完美运行.
任何人都可以帮我解决这个问题吗?

最佳答案
错误消息

  1. org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type
  2. [simple type,class com.enterprisemk.android.bcw.bincollection.WasteCollectionAreasContainer]:
  3. can not instantiate from JSON object (need to add/enable type information?)

表明Jackson库试图使用反射来反序列化你的类,它的原始名称和带注释的构造函数. ProGuard无法预见到这一点,因此它可能已删除重命名了该类及其构造函数.您可能需要明确地保留它们:

  1. -keep class com.enterprisemk.android.bcw.bincollection.WasteCollectionAreasContainer {

出于同样的原因,可能还需要保留其他类似的类/字段/方法.

猜你在找的Android相关文章