注入 Enum 可以使用字符串直接注入,或者借助 org.springframework.beans.factory.config.FieldRetrievingFactoryBean,下面以注入 FastJson 的 SerializerFeature 和自定义 enum 为例.
1 | package com.alibaba.fastjson.serializer; |
1 | public enum Color { |
enum.xml
1 |
|
InjectEnum.java
1 | import com.alibaba.fastjson.JSON; |
输出:
1 | {"color":"RED","features":["QuoteFieldNames","UseSingleQuotes"]} |