1 package com.fasterxml.jackson.failing; 2 3 import com.fasterxml.jackson.annotation.JsonValue; 4 5 import com.fasterxml.jackson.databind.*; 6 7 public class EnumDeserializationFromInt1850Test extends BaseMapTest 8 { 9 enum Example1 { 10 A(101); 11 final int x; Example1(int x)12 Example1(int x) { this.x = x; } 13 @JsonValue code()14 public int code() { return x; } 15 } 16 17 enum Example2 { 18 A(202); 19 @JsonValue 20 public final int x; Example2(int x)21 Example2(int x) { this.x = x; } 22 } 23 testEnumFromInt1850()24 public void testEnumFromInt1850() throws Exception 25 { 26 final ObjectMapper mapper = newJsonMapper(); 27 28 String json = mapper.writeValueAsString(Example1.A); 29 Example1 e1 = mapper.readValue(json, Example1.class); 30 assertEquals(Example1.A, e1); 31 32 json = mapper.writeValueAsString(Example2.A); 33 Example2 e2 = mapper.readValue(json, Example2.class); 34 assertEquals(Example2.A, e2); 35 } 36 } 37