first of all, i am quite new to spring (web mvc). I am building a RESTful service for my frontend. I am sending a JSON data but one object in that data was not parsed when it is received by spring.
Here is my data
JSON Data
{
"comments" : []
"description": "Testing",
"images": "[\"path1\", \"path2\", \"path3\"]",
"profile": {
"id": 21234,
"fullname": "John Michael Doe",
"nickname": "Doe",
"email": "jdoe@email.com",
"profilePic": "/some/host/pic"
}
}
RequestMapper
@RestController
@RequestMapping("/wish")
public class WishlistController extends WishlistConverter{
/* Some @Autowired here for services... */
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> create(@RequestBody RestWishlist input){
try {
logger.info("create({})",input);
Wishlist wish = convert(input);
wishlistService.create(wish);
return new ResponseEntity<>(HttpStatus.OK);
} catch (Exception e) {
logger.error("Error: {}",e.getMessage());
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
}
}
RestWishlist
public class RestWishlist {
private Long wishId;
private List<RestComment> comments;
private String description;
private String images;
private Long createdAt;
private Long updatedAt;
private RestProfile profile;
/* Getters and Setters here */
}
RestProfile
public class RestProfile {
private Long id;
private String fullname;
private String nickname;
private String email;
private String profilePic;
/* Getters and Setters Here */
}
RestComment
public class RestComment {
private Long commentId;
private String description;
private RestProfile profile;
private Long createdAt;
private Long updatedAt;
/* Getters and Setters Here */
}
Now, i have a problem getting the "profile" part of my JSON data, log file show this
2017-12-03 20:50:31.740 INFO 10212 --- [nio-8080-exec-1] c.s.s.web.controller.WishlistController : create(RestWishlist [wishId=null, comments=[], description=Testing, images=["path1", "path2", "path3"], createAt=null, updatedAt=null])
2017-12-03 20:50:31.740 INFO 10212 --- [nio-8080-exec-1] c.s.s.services.impl.WishlistServiceImpl : create(Wishlist [wishId=null, comments=[], description=Testing, images=["path1", "path2", "path3"], createAt=null, updatedAt=null])