2014-06-12 22 views
1

与spring-data-dynamoDB demo一样,我使用散列和范围键创建了我的应用程序,但无法使用POST将任何数据发布到我的表中,因为以下异常,如何发布到带有hash +范围键的URL Spring Data DynamoDB

{cause: {cause: {cause: null,message: null}, message: "N/A (through reference chain: pkg.Test["id"])"}, message: "Could not read JSON: N/A (through reference chain: pkg.Test["id"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: N/A (through reference chain: pkg["id"])" 
} 

我的域类,

@DynamoDBTable(tableName = "test") 
public class Test implements Serializable{ 

private static final long serialVersionUID = 1L; 

@Id private TestId testId; 
private String description; 
private String testing; 

@DynamoDBHashKey(attributeName="id") 
public String getId() { 
    return testId != null ? testId.getId() : null; 
} 

public void setId(String id) { 
    if(testId == null){ 
     testId = new TestId(); 
    } 
    this.setId(id); 
} 

@DynamoDBRangeKey(attributeName="name") 
public String getName() { 
    return testId != null ? testId.getName() : null; 
} 

public void setName(String name) { 
    if(testId == null){ 
     testId = new TestId(); 
    } 
    this.setName(name); 
} 

@DynamoDBAttribute(attributeName="description") 
public String getDescription() { 
    return description; 
} 

public void setDescription(String description) { 
    this.description = description; 
} 

@DynamoDBAttribute(attributeName="testing") 
public String getTesting() { 
    return testing; 
} 

public void setTesting(String testing) { 
    this.testing = testing; 
} 

public TestId getTestId() { 
    return testId; 
} 

public void setTestId(TestId testId) { 
    this.testId = testId; 
} 
} 

和我TestId类

public class TestId implements Serializable{ 

private String id; 
private String name; 

@DynamoDBHashKey 
public String getId() { 
    return id; 
} 

public void setId(String id) { 
    this.id = id; 
} 

@DynamoDBRangeKey 
public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 
} 

我想我已经正确地创建了Domain类,但是将数据发布到其中的正确过程是什么。我已经试过了, 网址:

http://localhost:8080/tests 

请求正文:

{"testId": {"id": "test", "name": "z"}, "description": "Awesome Guy", "testing": "x"} 

{"id": "test", "name": "z", "description": "Awesome Guy", "testing": "x"} 

但所有显示异常,因为我上面提到的,但我已经给ID在requestbody中正确的属性。 将数据发布到我的表中的正确过程是什么?和spring-data-rest解析有什么问题吗?如上所述here

回答

0

setId()方法似乎是自我调用。您可能需要调用testId.setId()而不是this.setId()。

+0

谢谢MGhostSoft,它的工作很好,但是我被这部分代码卡住了,** public TestId getTestId(){ return testId; } public void setTestId(TestId testId){this.testId = testId; } **,我想我需要为它编写marshallers。刚刚删除,并正常工作。 – jAddict

相关问题