1

I am developing a application in Spring-data-rest. I am testing the POST requests from POSTMAN client to test whether the data is inserting into DB.In my DB i have a cartItems table. I am able to POST the data while i POST the JSON as Follows: merchandise, cart and merchandiseType are foreign key references.

 {
"rate": 500,
"quantity": 1,
"amount": 500,
"createdAt": "2015-04-12T23:40:00.000+0000",
"updatedAt": "2015-04-14T21:35:20.000+0000",
"merchandise": "http://localhost:8080/sportsrest/merchandises/10",
"cart":"http://localhost:8080/sportsrest/carts/902",
"merchandiseType":"http://localhost:8080/sportsrest/merchandiseTypes/1"
  }

But while i POST the data as below i am getting error: Instead of URL for merchandise i placed the merchandise JSON which i already tested the POST request for merchandise table JSON:

 {
"rate": 500,
"quantity": 1,
"amount": 500,
"createdAt": "2015-04-12T23:40:00.000+0000",
"updatedAt": "2015-04-14T21:35:20.000+0000",
"merchandise": {
   "id": 4,
   "shortDescription": "white football",
   "rate": 500,
   "updatedAt": "2015-04-24T18:30:00.000+0000",
   "createdAt": "2015-04-20T18:30:00.000+0000",
   "longDescription": "test description for binary 1001",
   "type": "1"
    },
"cart":"http://localhost:8080/sportsrest/carts/902",
"merchandiseType":"http://localhost:8080/sportsrest/merchandiseTypes/1"

}

I am getting following ERROR:

 {
"cause": {
"cause": {
"cause": null,
"message": "Template must not be null or empty!"
  },
"message": "Template must not be null or empty! (through reference chain:   co.vitti.sports.bean.CartItem[\"merchandise\"])"
 },
 "message": "Could not read JSON: Template must not be null or empty! (through reference chain: co.vitti.sports.bean.CartItem[\"merchandise\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Template must not be null or empty! (through reference chain: co.vitti.sports.bean.CartItem[\"merchandise\"])"
}

Can some one please help me to why i am getting this error. Thanks.

MAK
  • 390
  • 2
  • 8
  • 25

2 Answers2

0

I guess you didn't provide the Content-Type: application/json header.

Jean Duarte
  • 170
  • 5
  • thanks for replay. I provided the Content-Type as Application/json. Can we POST the link of reference table as JSON as i did above? – MAK Apr 23 '15 at 03:26
  • Hey, sorry for my hasty answer. I just didn't read thoroughly your question. By default Spring Data Rest will try to figure out what data sent are. To do so with associations it will consider URIs. If you really need to use the latter example you should write a custom deserializer. – Jean Duarte Apr 23 '15 at 19:06
  • it's ok. Thanks for your response. – MAK Apr 24 '15 at 04:54
0

Try to annotate your "MerchandiseRepository" with "@RestResource(exported = false)".