How do I configure the date formatter through Genson/Jersey?

后端 未结 1 858
甜味超标
甜味超标 2021-01-20 03:15

I\'m using Jersey for my RESTful services and Genson to perform my JSON/POJO conversion. There\'s no setup for Genson, I just drop it into the classpath and it just works,

1条回答
  •  生来不讨喜
    2021-01-20 03:44

    To configure Genson instances you can use Genson.Builder class (it is similar to Gson on this point). Then you have to inject it with Jersey.

    @Component
    @Provider
    public class GensonProvider implements ContextResolver {
       private final Genson genson = new Genson.Builder().setDateFormat(yourDateFormat).create();
    
        @Override
       public Genson getContext(Class type) {
         return genson;
       }
    }
    

    You might also want to have a look at how Genson is integrated into Jersey here.

    0 讨论(0)
提交回复
热议问题