杰克逊忽略了父母的所有领域

时间:2017-05-08 13:03:51

标签: java spring-boot jackson

我有2个课程ParentChild

public abstract class Parent implements Serializable{
    protected String id;
    protected String deletedAt;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getDeletedAt() {
        return deletedAt;
    }
    public void setDeletedAt(String deletedAt) {
        this.deletedAt = deletedAt;
    }
}

public class Child extends Parent{
    private String name;
    public String getName(){
    ...
}

当我加载Child并试图像这样:

Child c = getChildFromDb();
c.getId();

这是我的杰克逊配置:

JacksonConfig

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

@Configuration
public class JacksonConfig {

    @Bean
    @Primary
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        objectMapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
        return objectMapper;
    }
}

ID为null但名称在那里。我做错了什么?

0 个答案:

没有答案