![]() ![]() The ObjectMapper is one of the most important aspects of Jackson. The custom serializer is registered using addSerializer.VersionUtil is a handy Jackson utility that will attempt to intelligently version the module. The name argument is useful for detecting when a module is registered multiple times in order to avoid collisions. super is called with a name and a version.I personally have never needed to use something different. This very basic implementation that Jackson provides is sufficient for most cases. The custom module extends SimpleModule.There are a few things to note in the above code: ĪddSerializer(Interval.class, new IntervalSerializer()) Instead, I want to return a start and end property with their respective values. That is pretty terrible to read as a human, and I definitely do not want to force all clients of my API to parse that string. For example, the Interval class is serialized as a dash-separated string by default. One great use case of a custom serializer is for overriding default behavior. Fortunately, Jackson provides a way to write custom code and control how any object is translated to JSON. However, sometimes more complex translation is necessary and the out-of-the-box features don’t cut it. It comes packaged with a number of features that make it easy to turn a Plain Old Java Object (POJO) into JSON with little effort. Jackson is a great framework for translating Java to JSON. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |