我在我的Neo4J托管扩展中实现了 EntityResource 类,其中 Entity 模型和 EntityAdapter 适配器覆盖了XmlAdapter . 部署到服务器时一切正常 . 该模型使用适配器来封送实体,资源也相应地响应 .

但是在我使用Neo4J线束和Neo4JRule的测试类(下面)中,完全忽略了 EntityAdapter ,因此我收到了带有不需要值的 Entity 的默认封送版本 .

@Rule
public Neo4jRule neo4j = new Neo4jRule()
        .withFixture( "CREATE ({name:'test'})" )
        .withExtension( "/test", EntityResource.class );


@Test
public void testRead() {
    // Given
    URI serverURI = neo4j.httpURI();

    String uri = serverURI.toString() + "test/entities/test";
    HTTP.Response response = HTTP.GET( uri );

    // Then it should reply
    assertEquals( response.toString(), 200, response.status() );
    System.out.println( response.toString() );

}

必须正确设置适配器才能在资源中工作,因此我猜测它与测试如何搜索正确的适配器有关 . 无论如何,我的 class 声明如下

@XmlJavaTypeAdapter( EntityAdapter.class )
public class Entity {

为什么在服务器使用时不使用适配器进行测试?如何解决?