0
우선, 나는 봄에 매우 익숙합니다. 나는 프론트 엔드를위한 RESTful 서비스를 구축 중이다. JSON 데이터를 보내고 있지만 그 데이터에서 하나의 객체는 봄에 수신되면 파싱되지 않았습니다. 여기 스프링 부트 웹은 객체로 중첩 된 json을 구문 분석 할 수 없습니다.
는JSON 데이터 내 데이터입니다
{
"comments" : []
"description": "Testing",
"images": "[\"path1\", \"path2\", \"path3\"]",
"profile": {
"id": 21234,
"fullname": "John Michael Doe",
"nickname": "Doe",
"email": "[email protected]",
"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
,536,913,632 10public 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 */
}
이제
public class RestComment {
private Long commentId;
private String description;
private RestProfile profile;
private Long createdAt;
private Long updatedAt;
/* Getters and Setters Here */
}
RestComment, 난, 내 JSON 데이터의 "프로필"부분을 얻기에 문제가있는 파일 쇼 로그이
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])
표시되는 프로파일 변수를 추가
후 전에
아래 참조 받은거야? – swapnil
profile 속성 값이 null이면 결과 JSON에서 건너 뛸 수 있습니다. – swapnil
@swapnil - JSON 데이터를 기반으로 봄에 보내진 "프로필"에 값이 있습니다. 내 JSON 데이터를 참조하십시오. – lemoncodes