1 package com.fasterxml.jackson.failing;
2 
3 import com.fasterxml.jackson.annotation.*;
4 
5 import com.fasterxml.jackson.databind.*;
6 
7 public class KevinFail1410Test extends BaseMapTest
8 {
9     enum EnvironmentEventSource { BACKEND; }
10 
11     @JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="source")
12     @JsonSubTypes({
13             @JsonSubTypes.Type(value = BackendEvent.class, name = "BACKEND")
14     })
15     static abstract class EnvironmentEvent {
16         private String environmentName;
17         private String message;
18 
EnvironmentEvent()19         protected EnvironmentEvent() { } // for deserializer
EnvironmentEvent(String env, String msg)20         protected EnvironmentEvent(String env, String msg) {
21             environmentName = env;
22             message = msg;
23         }
getEnvironmentName()24         public String getEnvironmentName() { return environmentName; }
getSource()25         public abstract EnvironmentEventSource getSource();
getMessage()26         public String getMessage() { return message; }
27     }
28 
29     static class BackendEvent extends EnvironmentEvent {
30         private String status;
31 
32         private Object resultData;
33 
BackendEvent()34         protected BackendEvent() {} // for deserializer
35 
BackendEvent(String envName, String message, String status, Object results)36         public BackendEvent(String envName, String message, String status, Object results)
37         {
38             super(envName, message);
39             this.status = status;
40             resultData = results;
41         }
42 
create(String environmentName, String message, String status, Object results)43         public static BackendEvent create(String environmentName, String message,
44                 String status, Object results)
45         {
46             return new BackendEvent(environmentName, message,
47                     status, results);
48         }
49 
50         @Override
getSource()51         public EnvironmentEventSource getSource() {
52             return EnvironmentEventSource.BACKEND;
53         }
54 
getStatus()55         public String getStatus() {
56             return status;
57         }
58 
getResultData()59         public Object getResultData() {
60             return resultData;
61         }
62 
63         @Override
toString()64         public String toString() {
65             return String.format("(%s): %s", status, getMessage());
66         }
67     }
68 
testDupProps()69     public void testDupProps() throws Exception
70     {
71         ObjectMapper mapper = new ObjectMapper();
72         EnvironmentEvent event = new BackendEvent("foo", "hello", "bar", null);
73         String ser = mapper
74                 .writerWithDefaultPrettyPrinter()
75                 .writeValueAsString(event);
76         mapper.readValue(ser, EnvironmentEvent.class);
77         assertNotNull(ser);
78     }
79 }
80