ArrayList 使用Cloud Endpoints?

时间:2022-12-22 23:09:37

I use java to program an API with Google Cloud Endpoints and the Datastore. I just added a ArrayList<HashMap<String, String>> as a field of one of my entities but it seems not to be recognized by Cloud Endpoints. I use the Objectify framework.

我使用java来编写一个使用Google Cloud Endpoints和Datastore的API。我刚刚添加了一个ArrayList >作为我的一个实体的字段,但它似乎不被Cloud Endpoints识别。我使用Objectify框架。

At first I noticed some NullPointerException occuring because of it and then I saw that the field isn't even mentionned by the Datastore Viewer.

起初我注意到因为它发生了一些NullPointerException,然后我看到数据存储区查看器甚至没有提到该字段。

Is this type not supported by the datastore?

数据存储区不支持此类型吗?

2 个解决方案

#1


0  

The field should be supported, both by datastore and the cloud endpoints marshaller. Just bear in mind that empty collections are stored as null values on the datastore.

数据存储区和云端点编组器应支持该字段。请记住,空集合在数据存储区中存储为空值。

You'll have to init the collection upon retrieval in case the entity was stored with an empty collection.

如果实体与空集合一起存储,则必须在检索时初始化集合。

Having said that I Agree with @QPaysTaxes recommendation, in the long run you'll save yourself a lot of pain if you wrap that into a POJO. Which BTW can be referenced by ID instead of having to duplicate data all over the place.

说过我同意@QPaysTaxes的建议,从长远来看,如果你将它包装成POJO,你将会省去很多痛苦。哪个BTW可以通过ID引用,而不必在整个地方复制数据。

#2


0  

With Objectify you can store any POJO, can you check that the field appears by using the developer's console?

使用Objectify,您可以存储任何POJO,是否可以使用开发人员的控制台检查该字段是否显示?

By the way, a Cloud Endpoint can return any object (but not a primitive one, like int or boolean). So it won't be a problem on that matter.

顺便说一句,Cloud Endpoint可以返回任何对象(但不是原始对象,如int或boolean)。所以在这件事上不会有问题。

#1


0  

The field should be supported, both by datastore and the cloud endpoints marshaller. Just bear in mind that empty collections are stored as null values on the datastore.

数据存储区和云端点编组器应支持该字段。请记住,空集合在数据存储区中存储为空值。

You'll have to init the collection upon retrieval in case the entity was stored with an empty collection.

如果实体与空集合一起存储,则必须在检索时初始化集合。

Having said that I Agree with @QPaysTaxes recommendation, in the long run you'll save yourself a lot of pain if you wrap that into a POJO. Which BTW can be referenced by ID instead of having to duplicate data all over the place.

说过我同意@QPaysTaxes的建议,从长远来看,如果你将它包装成POJO,你将会省去很多痛苦。哪个BTW可以通过ID引用,而不必在整个地方复制数据。

#2


0  

With Objectify you can store any POJO, can you check that the field appears by using the developer's console?

使用Objectify,您可以存储任何POJO,是否可以使用开发人员的控制台检查该字段是否显示?

By the way, a Cloud Endpoint can return any object (but not a primitive one, like int or boolean). So it won't be a problem on that matter.

顺便说一句,Cloud Endpoint可以返回任何对象(但不是原始对象,如int或boolean)。所以在这件事上不会有问题。