I have 2 classes Parent
and a 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(){
...
}
when i load the Child and try to go like this :
Child c = getChildFromDb();
c.getId();
and this is my jackson config:
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;
}
}
the ID is null but the Name is there. What i am doing wrong ?
It turns out to be a problem with the DB Driver of 'rethink' for some reason rethink DB driver ignored the fields of the parent class and this caused that those fields were never stored in the DB so they were never retrieved. Changed the DB with its driver to MongoDB and it works perfectly now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.