我正在试图弄清楚如何让它发挥作用。我有一个类Connection,我想在用户对我们的API发布POST时在数据存储区中创建并保留。这就是端点的样子:
/
由于此异常,端点中的代码不会触发:
@Api(
name = "connect",
version = "v1",
defaultVersion = AnnotationBoolean.TRUE)
public class ConnectionEndpoint {
@PersistenceContext
protected static EntityManager entityManager = EMF.get().createEntityManager();
...
@ApiMethod(
name = "connections.create",
path = "connections/{schema}",
httpMethod = HttpMethod.POST)
public Connection createConnection(@Named("schema") String schema, Connection connection) throws BadRequestException {
// Code that checks permission and persists the connection if everything checks out
}
...
}
Connection类看起来像这样:
com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: Can not construct instance of com.analysis_engine.model.connect.BaseConnectionService, problem: abstract types can only be instantiated with additional type information
BaseConnectionService类如下所示:
@Entity
@Table(name = "Connection")
public class Connection {
...
@OneToOne(orphanRemoval = true, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private BaseConnectionService service;
...
}
扩展BaseConnectionService的类如下所示:
@Entity
@Table(name="ConnectionService")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "Service", discriminatorType = DiscriminatorType.STRING, length = 64)
abstract public class BaseConnectionService {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Key key;
...
}
所以我希望能够使用任何类型的ConnectionService POST一个Connection对象。它可以工作,如果我在服务器端完成所有这一切,问题是让杰克逊正确地反序列化POSTed数据。