Skip to content

Can't deserialize a class extending ArrayList #318

@gwendal-lecren

Description

@gwendal-lecren

Environment details

  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    com.google.cloud:google-cloud-firestore:1.33.0
  2. OS type and version:
    Windows 10
  3. Java version:
    Java 11
  4. firestore version(s):
    1.33.0

Steps to reproduce

  1. Load a class having a property extending the ArrayList class (InternalFieldDefinition in my example)

Code example

package io.test;

import java.util.ArrayList;

public class InternalFieldPath extends ArrayList<InternalMappingField> {

    public InternalFieldPath() {
        super();
    }

}
package io.test;

public class InternalFieldDefinition extends InternalModel {

    private String name;
    private InternalFieldPath path;

}

Stack trace

java.lang.RuntimeException: Could not deserialize object. Can't convert object of type java.util.ArrayList to type io.blendeez.common.domain.model.internal.InternalFieldPath (found in field 'fieldDefinitions.[0].sourceFieldPath')
	at com.google.cloud.firestore.CustomClassMapper.deserializeError(CustomClassMapper.java:563)
        at com.google.cloud.firestore.CustomClassMapper.convertBean(CustomClassMapper.java:544)

Any additional information below

It seems the case where a bean extends an ArrayList is not properly handled in CustomClassMapper (only Map):

  private static <T> T convertBean(Object o, Class<T> clazz, DeserializeContext context) {
    BeanMapper<T> mapper = loadOrCreateBeanMapperForClass(clazz);
    if (o instanceof Map) {
      return mapper.deserialize(expectMap(o, context), context);
    } else {
      throw deserializeError(
          context.errorPath,
          "Can't convert object of type " + o.getClass().getName() + " to type " + clazz.getName());
    }
  }

FYI while switching the class attribute to a list it works:

  public class InternalFieldDefinition {

    private String name;
    private List<InternalMappingField> path;

}

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/java-firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions