>

이 수업은 RestAPI 로 돌아가고 싶습니다   JSON 에 전화  형식

return ResponseEntity.ok().cacheControl(CacheControl.maxAge(5, TimeUnit.MINUTES))
                    .body(hotelChart2);

클래스 :

public class HotelChart2 {

    public HotelChart2() {
        super();
    }
    public class Statistics {
         double min;
         double max;
         double average;
         public Statistics() {
            super();
         }
        public Statistics(double min, double max, double average) {
            super();
            this.min = min;
            this.max = max;
            this.average = average;
        }
    }
    Map<LocalDateTime, DoubleSummaryStatistics> las24HPerHour;
    Map<LocalDate, Statistics> last30DPerDay;
    Map<LocalDate, Statistics> last3MPerDay;
    Map<LocalDate, Statistics> last6MPerDay;
    Map<LocalDate, Statistics> last1YPerDay;

    public Map<LocalDateTime, DoubleSummaryStatistics> getLas24HPerHour() {
        return las24HPerHour;
    }
    public void setLas24HPerHour(Map<LocalDateTime, DoubleSummaryStatistics> las24hPerHour) {
        las24HPerHour = las24hPerHour;
    }
    public Map<LocalDate, Statistics> getLast30DPerDay() {
        return last30DPerDay;
    }
    public void setLast30DPerDay(Map<LocalDate, Statistics> last30dPerDay) {
        last30DPerDay = last30dPerDay;
    }
    public Map<LocalDate, Statistics> getLast3MPerDay() {
        return last3MPerDay;
    }
    public void setLast3MPerDay(Map<LocalDate, Statistics> last3mPerDay) {
        last3MPerDay = last3mPerDay;
    }
    public Map<LocalDate, Statistics> getLast6MPerDay() {
        return last6MPerDay;
    }
    public void setLast6MPerDay(Map<LocalDate, Statistics> last6mPerDay) {
        last6MPerDay = last6mPerDay;
    }


    public Map<LocalDate, Statistics> getLast1YPerDay() {
        return last1YPerDay;
    }
    public void setLast1YPerDay(Map<LocalDate, Statistics> last1yPerDay) {
        last1YPerDay = last1yPerDay;
    }

}

그러나이 오류가 발생했습니다 :

Type definition error: [simple type, class com.tdk.api.json.HotelChart2$Statistics]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.tdk.api.json.HotelChart2$Statistics and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.tdk.api.json.HotelChart2["last3MPerDay"]->java.util.HashMap["2019-01-27"])
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:293)
    at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:103)
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:290)

  • 답변 # 1

    getters 를 추가해야합니다  당신의 내부 Statistics 에  클래스 (권장) 또는 fields 활성화   ObjectMapper 에 대한 가시성  레벨 :

    ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(mapper.getVisibilityChecker()
         .withFieldVisibility(JsonAutoDetect.Visibility.ANY));
    
    

관련 자료

  • 이전 c++ - 복합 데이터 유형에 glClearBufferData를 사용하여 이식 가능합니까?
  • 다음 android - 3 x 3 항목 가로 스크롤이있는 RecyclerView