1
我有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 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爲空,但名稱存在。我做錯了什麼?
輸入是什麼? – reos
@reos找到任何孩子或所有孩子 –
什麼是你解析的json/xml? – reos