2013-05-15 67 views
1

我使用招搖,jaxrs_2.10.0版本1.2.3(1.2.2從剛升級這有相同的結果)揚鞭列表有型「的任何」而不是適當類型

如果我有一個類像這樣:

public class XXXResponse 
{ 
    private List<Boolean> booleans; 
    private List<Byte> bytes; 
    private List<Short> shorts; 
    private List<Integer> integers; 
    private List<Long> longs; 
    private List<Float> floats; 
    private List<Double> doubles; 
    private List<String> strings; 
    private List<Date> dates; 

    // set/get methods 
} 

揚鞭報告爲:

{ 
    "integers": [ 
    "int" 
    ], 
    "bytes": [ 
    "any" 
    ], 
    "longs": [ 
    "any" 
    ], 
    "dates": [ 
    "any" 
    ], 
    "shorts": [ 
    "any" 
    ], 
    "strings": [ 
    "string" 
    ], 
    "doubles": [ 
    "any" 
    ], 
    "floats": [ 
    "any" 
    ], 
    "booleans": [ 
    "boolean" 
    ] 
} 

有什麼具體的魔術,我需要incant使「任何」轉成相應的類型?

回答

1

事實證明,在配置傑克遜的伎倆:

JacksonJsonProvider.java

@Provider 
@Produces(MediaType.APPLICATION_JSON) 
public class JacksonJsonProvider extends JacksonJaxbJsonProvider 
{ 
    private static ObjectMapper commonMapper = null; 

    public JacksonJsonProvider() 
    { 
     if(commonMapper == null) 
     { 
      ObjectMapper mapper = new ObjectMapper(); 

      mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 
      mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); 
      mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); 
      mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);  
      commonMapper = mapper; 
     } 

     super.setMapper(commonMapper); 
    } 
}