Send abstract classes via API

I'm currently trying to send something like this via. Cloud Endpoints:

public abstract class Transaction { //... } public class BuyTransaction extends Transaction { //... } public class UpgradeTransaction extends Transaction { //... } 

My API method for this is similar to

 @ApiMethod(...) public List<Transaction> getTransactions(User user) { /*...*/} 

But the created Endpoint-Libs contain only a transactional model, but ignore other classes. When I try this:

 List<? extends Transactions> 

The endpoint-lib generation completes completely and says that it is not supported. Is there any other way to send different classes that inherit from abstract classes by wiring?

+4
source share
1 answer

I do not think so. The general problem you are trying to solve does not always have a viable solution, since you need to combine all the properties of Transaction and any extending classes. Consider these classes:

 public abstract class Foo { //... } public class Bar extends Foo { public String prop; // getters and setters } public class Baz extends Foo { public Integer prop; // getters and setters } 

If the conglomeration of classes represented on the client side of Foo contains a prop field, which is String or Integer ?

If you want anything passing Foo be sent by wire, you must provide all the properties you want to send as part of Foo .

+2
source

Source: https://habr.com/ru/post/1484851/


All Articles