响应实体减少了Json对象

时间:2016-04-18 17:22:35

标签: java json spring spring-mvc

[
    {"id": 1, "city":
        {"id":4, "name": Warsaw}
    },
    {"id": 2, "city":4}
]  

为什么RestController没有回复完整对象而只回复了对象id中的id:2?总是存在这样的情况,即同一个对象city多次出现。

控制器:

 @RequestMapping(value = "/resource/company/offer", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE,)
    public ResponseEntity<?> getOfferByCompanyId(){
        Company company = companyRepository.findByUserId(userService.getUserWithAuthorities().getId());
        return Optional.ofNullable(offerRepository.findByCompany(company)).map(offers -> new ResponseEntity<>(offers.,HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
    }

的Json

[  
   {  
      "id":3,
      "description":"XYZ",
      "experience":1,
      "title":"XYZ",
      "industry":{  
         "id":1,
         "name":"IT"
      },
      "contractType":{  
         "id":1,
         "name":"HHH"
      },
      "city":{  
         "id":1,
         "name":"Warsaw",
         "region":{  
            "id":1,
            "name":"Mazovia"
         }
      },
      "company":{  
         "id":1,
         "name":"XYZ",
         "description":"XYZ",
         "avatar":"/user_images/70296679268537082326.png",
         "phone_number":"123456789",
         "post_code":"22-111",
         "address":"sda 2/13",
         "nip_number":"123456789",
         "www_address":"www.google.com",
         "city":1
      },
      "education":{  
         "id":1,
         "name":"QWE"
      },
      "competences":[  
         {  
            "id":2,
            "name":"QWE"
         }
      ],
      "jobPositions":[  
         {  
            "id":1,
            "name":"Programmer"
         }
      ]
   },
   {  
      "id":4,
      "description":"XYZ",
      "experience":2,
      "title":"XYZ",
      "industry":1,
      "contractType":1,
      "city":1,
      "company":1,
      "education":{  
         "id":2,
         "name":"ZWE"
      },
      "competences":[  
         {  
            "id":1,
            "name":"TYU"
         }
      ],
      "jobPositions":[  
         1
      ]
   }
]

0 个答案:

没有答案