有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java有没有一种方法可以将自定义对象列表放入cloudfirestore中的自定义对象中

我正在为一个使用cloud firestore的大学项目开发一个安卓应用程序,我想知道是否有可能在一个文档中有一个字段作为一个自定义对象数组(文档本身也是一个自定义对象) 我认为这是某种筑巢

我已经能够使用自定义对象(收据)。我有一个代表艺术品的字符串数组列表。现在,这些字符串被格式化,以便我可以解析它并读取价格、金额和文章的名称,但将来我可能需要添加更多数据。 我曾考虑使用子集合,但我需要能够直接下载整个文档

public class Ticket{

    // TICKET DATA
    private Date date;
    private double cashIn;
    ...


    // ARTICLES LIST DATA
    private ArrayList<String> basket;//What I want to change

    public Ticket(){
        // EMPTY CONSTRUCTOR NEEDED
    }
//With other constructors, setters and getters and parsing code

如果将ArrayList中的类型替换为自定义对象类型,则会出现以下错误:

Could not deserialize object. Can't convert object of type java.lang.String to type com.ereceipt.e_receipt.Objects.Article (found in field 'basket.[0]')

我使用以下方法在点击回调中从firebase到java对象进行“转换”:

DocumentSnapshot documentSnapshot = // Some query (kind of big, you might not need it)
Ticket ticket = documentSnapshot.toObject(Ticket.class);

以下是当前的Article类,稍后将为将来的功能进行升级:

public class Article{
    private String name;
    private int amount;
    private double unitprice;

    public Article(){

    }
    ...
}

我的数据库仅由一个名为收据的集合组成,文档如下所示:

receipt/basket (an array)
receipt/basket[0]/name (String)
receipt/basket[0]/amount (number)
receipt/basket[0]/unitprice (number)
receipt/cashIn (number)
receipt/store/name (String)
receipt/store/address (String)
receipt/store/message (String)
receipt/timestamp 

共 (0) 个答案