Despliegue del parcelero dando datos incorrectos

Estoy utilizando la biblioteca parceler para implementar interfaz Parcelable.

Tengo tal modelo

@Parcel(Parcel.Serialization.BEAN) public class Ads { private Long id; private String title; private String description; private AdsType adsType; private String phone; private String email; private String city; private Long categoryId; private ArrayList<Integer> creationDate; //TODO remove transient private transient ArrayList<Long> imageIds; private transient Long price; @SerializedName("adsCategory") private AdvCategory advCategory; public Ads() {} public Ads(String title, String description, AdsType adsType, String phone, String email, String city, Long categoryId, Long price, ArrayList<Long> imageIds) { this.title = title; this.description = description; this.adsType = adsType; this.phone = phone; this.email = email; this.city = city; this.categoryId = categoryId; this.price = price; this.imageIds = imageIds; } @ParcelConstructor public Ads(Long id, String title, String description, AdsType adsType, String phone, String email, String city, ArrayList<Long> imageIds, Long price, ArrayList<Integer> creationDate, AdvCategory advCategory) { this.id = id; this.title = title; this.description = description; this.adsType = adsType; this.phone = phone; this.email = email; this.city = city; this.imageIds = imageIds; this.price = price; this.creationDate = creationDate; this.advCategory = advCategory; } public Long getId() { return id; } public String getTitle() { return title; } public String getDescription() { return description; } public AdsType getAdsType() { return adsType; } public String getPhone() { return phone; } public String getEmail() { return email; } public String getCity() { return city; } public AdvCategory getAdvCategory() { return advCategory; } public void setAdvCategory(AdvCategory advCategory) { this.advCategory = advCategory; } public Long getCategoryId() { return categoryId; } public ArrayList<Long> getImageIds() { return imageIds; } public void setImageIds(ArrayList<Long> imageIds) { this.imageIds = imageIds; } public int getPrice() { //TODO replace with real price return new Random().nextInt(100000); } public void setPrice(Long price) { this.price = price; } public ArrayList<Integer> getCreationDate() { return creationDate; } public void setCreationDate(ArrayList<Integer> creationDate) { this.creationDate = creationDate; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Ads ads = (Ads) o; return id.equals(ads.id); } @Override public int hashCode() { int result = id.hashCode(); result = 31 * result + title.hashCode(); result = 31 * result + description.hashCode(); result = 31 * result + adsType.hashCode(); result = 31 * result + (phone != null ? phone.hashCode() : 0); result = 31 * result + (email != null ? email.hashCode() : 0); result = 31 * result + (city != null ? city.hashCode() : 0); result = 31 * result + advCategory.hashCode(); result = 31 * result + (categoryId != null ? categoryId.hashCode() : 0); return result; } @Override public String toString() { return "Ads{" + "id=" + id + ", title='" + title + '\'' + ", description='" + description + '\'' + ", adsType=" + adsType + ", phone='" + phone + '\'' + ", email='" + email + '\'' + ", city='" + city + '\'' + ", creationDate='" + creationDate.toString() + '}'; } public static class List extends ArrayList<Ads> {} } 

Estoy envolviendo mi modelo y poniéndolo en intención.

  Intent adsDetailsIntent = new Intent(this, AdsDetailsActivity.class); Bundle details = new Bundle(); Ads advertisement = mAdsAdapter.getItem(position); details.putParcelable(AdsDetailsActivity.ADS_DETAILS, Parcels.wrap(advertisement)); Ads ads = Parcels.unwrap(details.getParcelable(AdsDetailsActivity.ADS_DETAILS)); Log.d("ads", ads.toString()); adsDetailsIntent.putExtras(details); startActivity(adsDetailsIntent); 

Y desempaquetar en la actividad

 mAdsDetails = Parcels.unwrap( (Parcelable) this.getIntent().getParcelableExtra(ADS_DETAILS)); 

pero a veces el campo "creationDate" tiene un valor incorrecto después de desempaquetar en la actividad.

He intentado registrarlo, y después de desempaquetar de Bundle – está bien, pero en la actividad – tiene datos raros.

Ejemplo:

desempaquetar del paquete inmediatamente después de crearlo

Los anuncios {id = 16, title = 'Mtitle', description = 'Mads', adsType = COMPRA, email = '+ 380932309046', creationDate = '[2015, 8, 8, 9, 27, 0, 350946000]}

desenrollar de la actividad intent.getExtra ()

Los anuncios {id = null, title = 'null', description = 'null', adsType = null, phone = 'null', email = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

No sé por qué, pero está creando una matriz con creationDate 1 tamaño y llenarlo con ceros.

Me di cuenta de que en su desempaquetar la clase

 mAdsDetails = Parcels.unwrap( (Parcelable) this.getIntent().getParcelableExtra(ADS_DETAILS)); 

¿Lo has probado de esta manera?

 mAdsDetails = Parcels.unwrap(this.getIntent().getExtras().get(ADS_DETAILS)); 

Creo que esto podría estar relacionado con la discrepancia entre el tipo de retorno int de la función #getPrice y el tipo Long del argumento de price al constructor anotado con @ParcelConstructor .

Esto resultará en código generado que:

  1. escribe un entero en el paquete para la serialización
  2. intenta leer un tipo complejo, más grande después de la deserialización
  3. la deserialización continúa, pero efectivamente la lectura de basura ya que los métodos readFoo se llaman con el "error" de compensación en el buffer

Específicamente, al inspeccionar el código generado por Parceler y depurar el mismo problema en mi código, encontré que:

  • los tipos primitivos se escriben directamente en la parcela como un solo valor
  • los tipos complejos (como los envoltorios para tipos primitivos) se escriben con dos valores: uno para null frente a no null como un indicador y, a continuación, posiblemente, el valor real si no es null

Vea este problema que hice para el proyecto Parceler:

https://github.com/johncarl81/parceler/issues/234

  • ¿Cómo obtener la lista de aplicaciones recientes con Android API 21 Lollipop?
  • ¿Cómo enviar parámetros desde un clic de notificación a una actividad?
  • Cómo crear mi propia biblioteca android y alojarla
  • ¿Qué es SortedList <T> trabajando con RecyclerView.Adapter?
  • ActivityNotFoundException cuando targetClass del paquete diferente en PreferenceScreen
  • ¿Cuál es la diferencia entre los paquetes android.opengl y javax.microedition.khronos.opengles?
  • ¿Pueden dos aplicaciones diferentes tener el mismo nombre de paquete?
  • ¿Cómo hacer referencia a los "activos" de Android a través de paquetes?
  • Cordova + Marco iónico - ¿Cómo cambiar el nombre del paquete con seguridad?
  • No se puede instalar Xamarin.Android.Support.v4
  • ¿Guarda Android los archivos .apk? ¿si es así, donde?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.