杰克逊Included.NON_DEFAULT不工作在2.7.0
我想从杰克逊2.3升级到杰克逊2.7,并且它似乎@JsonIgnore(Include.NON_DEFAULT)行为已更改。 用下面的代码杰克逊Included.NON_DEFAULT不工作在2.7.0
package jackson; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Test {
public static void main (String args[]) throws Exception {
MyClass foo = new MyClass();
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writeValueAsString(foo));
}
public static enum MyEnum { A, B, C };
public static class MyClass {
public String name = "John";
@JsonInclude(Include.NON_DEFAULT)
public MyEnum myEnum = MyEnum.A;
}
}
我得到使用2.7的输出:以下使用2.3
{"name":"John","myEnum":"A"}
和:
{"name":"John"}
如何使用2.7版本复制在2.3的行为?
回答:
根据the bug ticket我把这个,它正在按预期和该功能可以通过结构化类的实现:
@JsonInclude(JsonInclude.Include.NON_DEFAULT) public static class MyClass {
@JsonInclude(JsonInclude.Include.ALWAYS)
public String name = "John";
public MyEnum myEnum = MyEnum.A;
}
见票从笔者更详尽的解释。
以上是 杰克逊Included.NON_DEFAULT不工作在2.7.0 的全部内容, 来源链接: utcz.com/qa/262839.html