2017-05-08 65 views
1

我有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 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爲空,但名稱存在。我做錯了什麼?

+0

輸入是什麼? – reos

+0

@reos找到任何孩子或所有孩子 –

+0

什麼是你解析的json/xml? – reos

回答

0

由於某種原因,重新考慮DB驅動忽略了父類的字段,導致這些字段從未存儲在數據庫中,因此從未被檢索,結果是「重新考慮」的DB驅動程序出現問題。 用它的驅動程序將數據庫更改爲MongoDB,現在它完美運行。