我有2个课程Parent
和Child
。
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();
这是我的杰克逊配置:
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但名称在那里。我做错了什么?