How to make Jersey/Jackson serialize empty list; single element list as an array

前端 未结 4 1854
青春惊慌失措
青春惊慌失措 2021-01-18 13:14

Using Jersey and Jackson to create a REST interface, how do I get List fields to be serialized as a list when there are 0 or 1 elements in them. For example:



        
4条回答
  •  青春惊慌失措
    2021-01-18 13:21

    I managed to solve JSON array "bug" in recent Jersey json library (v1.14 Sep 2012). Secret ingredient is JSONConfiguration and ContextResolver magic. See my following post it has a full code example, customized ContextResolver and rest Application class might be somewhat fuzzy logic in first look.

    How to serialize Java primitives using Jersey REST

    Primitives and zero or single-element List array are properly serialized to JSON document.

提交回复
热议问题