2013-12-11 58 views
0

我有一個Space對象,我寫了一個自定義序列化器和反序列化器。現在我已經將這個對象包裝在一個簡單的對象中用於某些上下文。我想要做的是序列化/反序列化這個包裝。在JSON反序列化過程中出現NullPointerException異常

我的空間對象序列化/反序列化罰款。我只是得到試圖反序列化時出現以下異常:

java.lang.NullPointerException 
    at org.codehaus.jackson.impl.ReaderBasedParser._skipWSOrEnd(ReaderBasedParser.java:1477) 
    at org.codehaus.jackson.impl.ReaderBasedParser.nextToken(ReaderBasedParser.java:368) 
    at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:690) 
    at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580) 
    at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732) 
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863) 
    at com.newoak.noc.curve.model.tests.ModelParamsTest.deserializeGraph(ModelParamsTest.java:100) 
    at com.newoak.noc.curve.model.tests.ModelParamsTest.testSerializationDeserialization(ModelParamsTest.java:113) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 

這裏是我的異常被拋出:

public ModelParamGraph deserializeGraph(String json) throws JsonGenerationException, JsonMappingException, IOException 
    { 
     ObjectMapper mapper = new ObjectMapper(); 
     SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null)); 
     testModule.addSerializer(new SpaceJsonSerializer()); 
     testModule.addDeserializer(Space.class, new SpaceJsonDeserializer()); 
     mapper.registerModule(testModule); 

     ModelParamGraph space = mapper.readValue(json, ModelParamGraph.class); 

     return space; 
    } 

這是我的包裝:

public class ModelParamGraph implements Serializable 
{ 

private static final long serialVersionUID = 6123736933251596579L; 

@JsonSerialize(using=SpaceJsonSerializer.class) 
@JsonDeserialize(using=SpaceJsonDeserializer.class) 
public Space<TModelParam> paramSpace; 

public String source; 

public Date date; 

private static Log log_ = LogFactory.getLog(ModelParamGraph.class); 

public ModelParamGraph(){} 

public ModelParamGraph(String source, Date date) 
{ 
    setSource(source); 
    setDate(date); 

    log_.debug("Creating ModelParam Graph"); 
    setParamSpace(new Space<TModelParam>()); 
} 

public Space<TModelParam> getParamSpace() 
{ 
    return paramSpace; 
} 

public void setParamSpace(Space<TModelParam> paramSpace) 
{ 
    this.paramSpace = paramSpace; 
} 

public void addParameter(TModelParam param, TModelParam parent) 
{ 
    if (paramSpace.getRootData() == null) 
    { 
     paramSpace.addData(param, true); 
    } 
    else 
    { 
     paramSpace.addData(param); 
    } 

    if (parent != null) 
    { 
     paramSpace.link(parent, param, "parent"); 
    } 
} 

public String getSource() 
{ 
    return source; 
} 

public void setSource(String source) 
{ 
    this.source = source; 
} 

public Date getDate() 
{ 
    return date; 
} 

public void setDate(Date date) 
{ 
    this.date = date; 
} 

}

任何幫助將不勝感激!謝謝!

+0

'json'可能是null嗎? –

+0

不,json從之前的序列化中正確格式化json – bjoern

+0

好吧,讓我們嘗試重現。發佈'json','SpaceJsonSerializer'和'SpaceJsonDeserializer'的值。 –

回答

0

無法解決此問題。 NullPointer異常是從傑克遜內部拋出。聽起來這可能是他們最終的錯誤。

相關問題