spring-data-rest의 문서에서 자체 objectMapper 구현을 사용한다는 것을 발견했습니다.
이 objectMapper를 재사용 할 수 있는지 알고 싶습니다. 그래서 spring-data-rest
엔드 포인트 에서와 동일한 엔티티 표현을 가질 수 있습니다.
예를 들어, jackson objectMapper 빈이 없으면
끝점 : GET / api / companies
"createdDate": { "content": "2016-12-25T12:39:03.437Z" }, "lastModifiedDate": null, "createdById": null, "lastModifiedById": null, "active": true, "name": "A6", "addressSecondary": null, "foundingDate": { "content": "2016-01-01" },
하지만 내 컨트롤러에는 다음이 있습니다.
"createdDate": {
"nano": 437000000,
"epochSecond": 1482669543
},
"lastModifiedDate": null,
"createdById": null,
"lastModifiedById": null,
"active": true,
"name": "A6",
"addressSecondary": null,
"foundingDate": {
"year": 2016,
"month": "JANUARY",
"era": "CE",
"dayOfYear": 1,
"dayOfWeek": "FRIDAY",
"leapYear": true,
"dayOfMonth": 1,
"monthValue": 1,
"chronology": {
"calendarType": "iso8601",
"id": "ISO"
}
이것은 내 자신의 컨트롤러 구현입니다.
@RequestMapping(method = RequestMethod.GET, value = "companies", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<?> testRead() {
List<Customer> customerRepositoryList = customerRepository.findAll();
Resources<Customer> resources = new Resources<>(customerRepositoryList);
return ResponseEntity.ok(resources);
}
내 코드에 objectMapper에 대한 빈이 없습니다.
동일한 직렬화를 어떻게 얻을 수 있습니까?
LocalDate 및 LocalDateTime 필드를 올바르게 출력하고 싶다고 생각 합니다. 그렇다면 프로젝트에 다음 종속성을 추가하십시오.
<!-- JDK 8 DateTime support for Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
필드에 대한 이러한 주석 :
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate date;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime dateTime;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다