Java 以JSON为参数的非托管扩展

Java 以JSON为参数的非托管扩展,java,json,neo4j,Java,Json,Neo4j,我正在尝试构建一个扩展,以便在neo4j中动态插入一些数据,但没有效果 这是我的分机码: @Path("/inserter") public class Inserter { private final GraphDatabaseService db; public Inserter(@Context GraphDatabaseService db){ this.db = db; } @POST @Consumes

我正在尝试构建一个扩展,以便在neo4j中动态插入一些数据,但没有效果

这是我的分机码:

@Path("/inserter")
public class Inserter {

    private final GraphDatabaseService db;

    public Inserter(@Context GraphDatabaseService db){
        this.db = db;
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("/insert")
    public void insert(Person x){   
        
        Transaction tr = db.beginTx();
        
        //Do something
        
        tr.success();
        tr.finish();
    }
}
这是我的个人目标:

package org.neo4j.server.plugin.plugin.messages;

public class Person {
    public String name;
    public int id;
    public String email;
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
}
我尝试了很多不同的方法,但到目前为止没有一种有效。使用上面的代码时,会出现415错误,称为“不支持的媒体类型”

我试图将jackson json提供程序添加到我的项目中。它改变了我的错误,但我不知道如何处理。错误现在是:

错误500 com.fasterxml.jackson.databind.ObjectWriter.getFactory()Lcom/fasterxml/jackson/core/JsonFactory

java.lang.NoSuchMethodError:com.fasterxml.jackson.databind.ObjectWriter.getFactory()Lcom/fasterxml/jackson/core/JsonFactory

为了测试我的扩展,我使用Google REST控制台,将RequestUri设置为localhost:7474/myextensions/inserter/insert,内容类型设置为application/json,请求主体如下所示:

{“id”:100,“name”:“Bibi”,“email”:“yopmail”}

编辑:这是maven依赖关系树(不确定它是否与给我带来麻烦的完全相同,因为我在提出问题后更改了很多代码)

“不支持的媒体类型”错误是由于您的方法和ajax调用中存在一些不匹配。在这里我可以看到你的方法是post,所以你必须通过post格式调用这个方法

看看它是否有效

json_数组*=[{“id”:100,“name”:“Bibi”,“email”:“yopmail”}]


您的
NoSuchMethodError
可能存在,因为您混合了Jackson版本。这是一种可能性,但我的项目只使用一个版本。也许Neo4j正在使用另一个我看不到的版本。你能发布
mvn dependency:tree
的输出来找出原因吗?这看起来很像是项目库的版本错误。你用的是什么版本的neo4j和jackson?@PeterNeubauer,结果是在我的编辑中我正在用REST控制台写一篇文章,它仍然不起作用
[INFO] org.neo4j.server.plugin:neo4j-antvoice-plugin:jar:0.0.1-SNAPSHOT
[INFO] +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:2.7.5:compile
[INFO] |  +- xml-resolver:xml-resolver:jar:1.2:compile
[INFO] |  +- asm:asm:jar:3.3.1:compile
[INFO] |  +- org.apache.cxf:cxf-api:jar:2.7.5:compile
[INFO] |  |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.2.0:compile
[INFO] |  |  |  \- org.codehaus.woodstox:stax2-api:jar:3.1.1:compile
[INFO] |  |  +- org.apache.ws.xmlschema:xmlschema-core:jar:2.0.3:compile
[INFO] |  |  +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile
[INFO] |  |  \- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] |  +- org.apache.cxf:cxf-rt-core:jar:2.7.5:compile
[INFO] |  |  \- com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile
[INFO] |  +- org.apache.cxf:cxf-rt-bindings-soap:jar:2.7.5:compile
[INFO] |  |  \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.7.5:compile
[INFO] |  +- org.apache.cxf:cxf-rt-bindings-xml:jar:2.7.5:compile
[INFO] |  +- org.apache.cxf:cxf-rt-frontend-simple:jar:2.7.5:compile
[INFO] |  \- org.apache.cxf:cxf-rt-ws-addr:jar:2.7.5:compile
[INFO] |     \- org.apache.cxf:cxf-rt-ws-policy:jar:2.7.5:compile
[INFO] |        \- org.apache.neethi:neethi:jar:3.0.2:compile
[INFO] +- org.apache.cxf:cxf-rt-transports-http:jar:2.7.5:compile
[INFO] +- org.neo4j:neo4j:jar:2.0.0-M03:compile
[INFO] |  +- org.neo4j:neo4j-kernel:jar:2.0.0-M03:compile
[INFO] |  |  \- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] |  +- org.neo4j:neo4j-lucene-index:jar:2.0.0-M03:compile
[INFO] |  |  \- org.apache.lucene:lucene-core:jar:3.6.2:compile
[INFO] |  +- org.neo4j:neo4j-graph-algo:jar:2.0.0-M03:compile
[INFO] |  +- org.neo4j:neo4j-udc:jar:2.0.0-M03:compile
[INFO] |  +- org.neo4j:neo4j-graph-matching:jar:2.0.0-M03:compile
[INFO] |  +- org.neo4j:neo4j-cypher:jar:2.0.0-M03:compile
[INFO] |  |  +- org.scala-lang:scala-library:jar:2.10.0:compile
[INFO] |  |  \- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.3.1:compile
[INFO] |  \- org.neo4j:neo4j-jmx:jar:2.0.0-M03:compile
[INFO] +- org.neo4j:server-api:jar:2.0.0-M03:compile
[INFO] |  +- org.neo4j.3rdparty.javax.ws.rs:jsr311-api:jar:1.1.2.r612:compile
[INFO] |  +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  |  +- commons-lang:commons-lang:jar:2.4:compile
[INFO] |  |  +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO] |  \- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] |     \- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.2.1:compile
[INFO]    +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.2.1:compile
[INFO]    +- com.fasterxml.jackson.core:jackson-core:jar:2.2.1:compile
[INFO]    +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.1:compile
[INFO]    |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.2.1:compile
[INFO]    \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.2.1:compile
$.ajax({
type:'POST',
url :'http://localhost:8080/inserter/insert',
cache: false,
contentType: "application/json",
dataType: 'json',
data:json_array,
success:function(data){},
error:function(response,status) {}
});