jackSon序列化枚举为字节数组抛空指针异常
最近在使用jackson的时候遇到这样一个问题,jackson版本1.9.10
ObjectMapper mapper = new ObjectMapper(new SmileFactory()); mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY); mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, false); mapper.setAnnotationIntrospector(new NopAnnotationIntrospector()); System.out.println(mapper.writeValueAsBytes(ViewTime.FOREVER));
public enum ViewTime{ FOREVER(-1), SEVEN_DAY(0), ONE_MONTH(1),TWO_MONTH(2),THREE_MONTH(3),SIX_MONTH(4),ONE_YEAR(5); private int value; private ViewTime(int value) { this.value = value; } public int getValue() { return value; } public static ViewTime fromValue(int period) { switch(period) { case -1: return FOREVER; case 0: return SEVEN_DAY; case 1: return ONE_MONTH; case 2: return TWO_MONTH; case 3: return THREE_MONTH; case 4: return SIX_MONTH; case 5: return ONE_YEAR; } return null; } @Override public String toString() { return String.valueOf(value); }}