เป้าหมายของฉันคือการกำหนดค่าobjectMapperในทางที่มัน serialises @JsonPropertyองค์ประกอบซึ่งมีคำอธิบายประกอบกับ
ในการดำเนินการดังกล่าวฉันทำตามคำอธิบายนี้ซึ่งระบุวิธีกำหนดค่า objectmapper
ผมรวม objectmapper ที่กำหนดเองตามที่อธิบายไว้ที่นี่
อย่างไรก็ตามเมื่อคลาสNumbersOfNewEventsถูกทำให้เป็นอนุกรมมันยังคงมีแอตทริบิวต์ทั้งหมดใน json
ใครมีคำใบ้? ขอบคุณล่วงหน้า
แจ็คสัน 1.8.0 สปริง 3.0.5
CustomObjectMapper
public class CompanyObjectMapper extends ObjectMapper {
    public CompanyObjectMapper() {
        super();
        setVisibilityChecker(getSerializationConfig()
                .getDefaultVisibilityChecker()
                .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
                .withFieldVisibility(JsonAutoDetect.Visibility.NONE)
                .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
                .withSetterVisibility(JsonAutoDetect.Visibility.DEFAULT));
    }
}
servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <context:component-scan base-package="de.Company.backend.web" />
    <mvc:annotation-driven />
    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                    <property name="objectMapper" ref="jacksonObjectMapper" />
                </bean>
            </list>
        </property>
    </bean>
    <bean id="jacksonObjectMapper" class="de.Company.backend.web.CompanyObjectMapper" />
</beans>
NumbersOfNewEvents
public class NumbersOfNewEvents implements StatusAttribute {
    public Integer newAccepts;
    public Integer openRequests;
    public NumbersOfNewEvents() {
        super();
    }
}