cuba-platform / restapi

CUBA REST API Add-on
Apache License 2.0
8 stars 7 forks source link

Implement serialization of KeyValueEntity without using MetaClass #104

Open belyaev-andrey opened 4 years ago

belyaev-andrey commented 4 years ago

Environment

Description of the bug or enhancement

When a published service returns a KeyValue entity, its serialization to JSON fails because the metadata is null. We do not add metadata when returning entities from datastore, but add it in the UI when adding KVEntity to the container:

com.haulmont.cuba.gui.model.impl.KeyValueCollectionContainerImpl#updateEntityMetadata

During serialization we invoke

com.haulmont.cuba.core.global.MetadataTools#isEmbeddable(com.haulmont.chile.core.model.MetaClass) 

And got NPE.

See https://www.cuba-platform.com/discuss/t/exception-in-rest-controller/12424

Run the application add a Customer and then try to invoke a published service using http://localhost:8080/app/rest/v2/services/restapithouthgs_RestService/getBuyer URL

knstvk commented 4 years ago

KeyValueEntity can be obtained from different sources or created on-the-fly. So we cannot rely on presence of MetaClass in it. The only reliable solution is to serialize to JSON without using MetaClass at all.