3
注:傑克遜2.1.x.如何將JSON null反序列化爲NullNode而不是Java null?
問題很簡單,但到目前爲止我找不到解決方案。我瀏覽了現有的文檔等,無法找到答案。
的基類是這樣的:
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "op")
@JsonSubTypes({
@Type(name = "add", value = AddOperation.class),
@Type(name = "copy", value = CopyOperation.class),
@Type(name = "move", value = MoveOperation.class),
@Type(name = "remove", value = RemoveOperation.class),
@Type(name = "replace", value = ReplaceOperation.class),
@Type(name = "test", value = TestOperation.class)
})
public abstract class JsonPatchOperation
{
/*
* Note: no need for a custom deserializer, Jackson will try and find a
* constructor with a single string argument and use it
*/
protected final JsonPointer path;
protected JsonPatchOperation(final JsonPointer path)
{
this.path = path;
}
public abstract JsonNode apply(final JsonNode node)
throws JsonPatchException;
@Override
public String toString()
{
return "path = \"" + path + '"';
}
}
而且有問題的階級是這樣的:
public abstract class PathValueOperation
extends JsonPatchOperation
{
protected final JsonNode value;
protected PathValueOperation(final JsonPointer path, final JsonNode value)
{
super(path);
this.value = value.deepCopy();
}
@Override
public String toString()
{
return super.toString() + ", value = " + value;
}
}
當我嘗試反序列化:
{ "op": "add", "path": "/x", "value": null }
我想空值將被反序列化爲NullNode
,而不是Java null。到目前爲止我還找不到一種方法。
你是如何實現這一目標的?
(注:具體類的所有構造函數是@JsonCreator
s的適當@JsonProperty
註解 - 他們沒有問題的工作,我唯一的問題是JSON空處理)
對於什麼是值得的,這可能是一個錯誤,在HTTPS現在報告: //github.com/FasterXML/jackson-databind/issues/186 – StaxMan 2013-03-08 20:42:32