• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.failing;
2 
3 import java.util.*;
4 
5 import com.fasterxml.jackson.annotation.*;
6 
7 import com.fasterxml.jackson.databind.*;
8 import com.fasterxml.jackson.databind.testutil.NoCheckSubTypeValidator;
9 
10 public class TestSetterlessProperties501
11     extends BaseMapTest
12 {
13     static class Poly {
14         public int id;
15 
Poly(int id)16         public Poly(int id) { this.id = id; }
Poly()17         protected Poly() { this(0); }
18     }
19 
20     static class Issue501Bean {
21         protected Map<String,Poly> m = new HashMap<String,Poly>();
22         protected List<Poly> l = new ArrayList<Poly>();
23 
Issue501Bean()24         protected Issue501Bean() { }
Issue501Bean(String key, Poly value)25         public Issue501Bean(String key, Poly value) {
26             m.put(key, value);
27             l.add(value);
28         }
29 
30         @JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
getList()31         public List<Poly> getList(){
32             return l;
33         }
34 
35         @JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
getMap()36         public Map<String,Poly> getMap() {
37             return m;
38         }
39 
40 //        public void setMap(Map<String,Poly> m) { this.m = m; }
41 //        public void setList(List<Poly> l) { this.l = l; }
42     }
43 
44     /*
45     /**********************************************************
46     /* Unit tests
47     /**********************************************************
48      */
49 
50     // For [databind#501]
testSetterlessWithPolymorphic()51     public void testSetterlessWithPolymorphic() throws Exception
52     {
53         Issue501Bean input = new Issue501Bean("a", new Poly(13));
54         ObjectMapper m = new ObjectMapper();
55         assertTrue(m.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS));
56         m.activateDefaultTyping(NoCheckSubTypeValidator.instance,
57                 ObjectMapper.DefaultTyping.NON_FINAL);
58 
59         String json = m.writerWithDefaultPrettyPrinter().writeValueAsString(input);
60 
61         Issue501Bean output = m.readValue(json, Issue501Bean.class);
62         assertNotNull(output);
63 
64         assertEquals(1, output.l.size());
65         assertEquals(1, output.m.size());
66 
67         assertEquals(13, output.l.get(0).id);
68         Poly p = output.m.get("a");
69         assertNotNull(p);
70         assertEquals(13, p.id);
71     }
72 }
73