title: Jackson deserialization with anonymous classes
body: <p>I have been searching all day for something that answers this, but I have not had a lot of luck thus far. </p>
  
  <p>My question is straightforward: how do I deserialize an anonymous object correctly using Jackson.</p>
  
  <pre><code>private interface Interface1
  {
      int getValue();
  }
  
  public static void testAnonymousObject() throws IOException
  {
      ObjectMapper mapper = new ObjectMapper();
  
      mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
      mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
      mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
      mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
  
      Interface1 testObject = new Interface1()
      {
          private final int value = 5;
  
          @Override
          public int getValue()
          {
             return value;
          }
      };
  
      String json = mapper.writeValueAsString(testObject);
      System.out.println("JSON = " + json);
  
      Interface1 received = (Interface1) mapper.readValue(json, Object.class);
      System.out.println(received);
  }
  </code></pre>
  
  <p>The output of this is: JSON = ["com.foo.test.JacksonTest$1",{"value":5}] before I get an exception:</p>
  
  <p><em>Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize Class com.foo.test.JacksonTest$1 (of type local/anonymous) as a Bean</em>.</p>
  
  <p><strong>EDIT</strong> Just to clarify, both Jackson and XStream are able to serialize the object. But only XStream seems to be able to deserialize the object back. So this scenario can be made to work.</p>