• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.ser;
2 
3 import java.util.*;
4 
5 import com.fasterxml.jackson.annotation.*;
6 import com.fasterxml.jackson.databind.*;
7 
8 /**
9  * This unit test suite verifies that static fields and methods are
10  * ignored wrt serialization
11  */
12 public class TestStatics
13     extends BaseMapTest
14 {
15     /*
16     /**********************************************************
17     /* Annotated helper classes
18     /**********************************************************
19      */
20 
21     final static class FieldBean
22     {
23         public int x = 1;
24 
25         public static int y = 2;
26 
27         // not even @JsonProperty should make statics usable...
28         @JsonProperty public static int z = 3;
29     }
30 
31     final static class GetterBean
32     {
getX()33         public int getX() { return 3; }
34 
getA()35         public static int getA() { return -3; }
36 
37         // not even @JsonProperty should make statics usable...
getFoo()38         @JsonProperty public static int getFoo() { return 123; }
39     }
40 
41     /*
42     /**********************************************************
43     /* Unit tests
44     /**********************************************************
45      */
46 
testStaticFields()47     public void testStaticFields() throws Exception
48     {
49         ObjectMapper m = new ObjectMapper();
50         Map<String,Object> result = writeAndMap(m, new FieldBean());
51         assertEquals(1, result.size());
52         assertEquals(Integer.valueOf(1), result.get("x"));
53     }
54 
testStaticMethods()55     public void testStaticMethods() throws Exception
56     {
57         ObjectMapper m = new ObjectMapper();
58         Map<String,Object> result = writeAndMap(m, new GetterBean());
59         assertEquals(1, result.size());
60         assertEquals(Integer.valueOf(3), result.get("x"));
61     }
62 }
63