2017-12-03 8 views
0

まずは、私はかなり新しい(Web mvc)です。私はフロントエンドのためのRESTfulなサービスを構築しています。 JSONデータを送信していますが、そのデータが春に受信されたときに解析されていないというオブジェクトが1つあります。ここでSpringブートWebはオブジェクトにネストされた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

です今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 */ 
} 

RestComment

public class RestComment { 

    private Long commentId; 

    private String description; 

    private RestProfile profile; 

    private Long createdAt; 

    private Long updatedAt; 
    /* Getters and Setters Here */ 
} 

、私は私の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 + ", profile=" + profile + "]"; } 

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

の下を参照してください。受け取ったのですか? – swapnil

+0

profile属性の値がnullの場合、結果のJSONからスキップされる可能性があります。 – swapnil

+0

@swapnil - 私のJSONデータに基づいて私は春に送られました。 "profile"に値があります。私のJSONデータを見てください。 – lemoncodes

答えて

0

トレースの日後に問題が見つかりました。それは単純なバグであり、本当に、私のために、不注意です。

"profile"がjsonデータから正しく設定されました。ログに表示されない理由は、RestWishlistクラスのtoString()メソッドにプロファイルが含まれていないためです。私は唯一のサービスプロファイルオブジェクトからデータを送信することはありませんがtoString()方法

関連する問題