1

As in spring-data-dynamoDB demo, I have created my application with hash and range keys, but am unable to post any data into my Table using POST because the following exception,

{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"])"
}

My Domain Class,

@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;
}
}

and my TestId Class,

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;
}
}

I think I have created Domain class correctly but What is the correct procedure to Post data into it. I have tried, URL:

http://localhost:8080/tests

Request Body:

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

and

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

But all shows the exception as I mentioned above but I have given id attribute in requestbody correctly. What is the correct procedure to POST the data into my table? and Is there anything problem with spring-data-rest parsing? as mentioned here

jAddict
  • 395
  • 3
  • 6
  • 18

1 Answers1

0

The setId() method seems to be self-calling. You may want to call testId.setId() instead of this.setId().

MGhostSoft
  • 528
  • 4
  • 13
  • Thank you MGhostSoft, its working good but I got stuck with this part of the code, **public TestId getTestId() { return testId; } public void setTestId(TestId testId) { this.testId = testId; }**, I think I need to write marshallers for it. Just removed that and working fine. – jAddict Jun 16 '14 at 05:36