2017-12-03 9 views
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 10
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 */ 
} 

이제

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]) 
+0

표시되는 프로파일 변수를 추가

@Override public String toString() { return "RestWishlist [wishId=" + wishId + ", comments=" + comments + ", description=" + description + ", images=" + images + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + "]"; } 

@Override public String toString() { return "RestWishlist [wishId=" + wishId + ", comments=" + comments + ", description=" + description + ", images=" + images + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", profile=" + profile + "]"; } 

후 전에

아래 참조 받은거야? – swapnil

+0

profile 속성 값이 null이면 결과 JSON에서 건너 뛸 수 있습니다. – swapnil

+0

@swapnil - JSON 데이터를 기반으로 봄에 보내진 "프로필"에 값이 있습니다. 내 JSON 데이터를 참조하십시오. – lemoncodes

답변

0

그래서 추적 일 후에 문제를 발견했습니다. 그것은 단순한 버그이고 정말로 나를 위해 부주의합니다.

"프로필"이 json 데이터에서 올바르게 설정되었습니다. 로그에 나타나지 않는 이유는 RestWishlist 클래스의 toString() 메소드에 프로파일이 포함되어 있지 않기 때문입니다. 서비스 프로파일 객체로부터 데이터를 전송하는 것은 아니지만 I 만 toString() 방법