# 12.2 Json Configuration

JFinal officially provides three implementations of the Json abstract class: JFinalJson, FastJson, and Jackson. If you don't configure it, the default implementation used is JFinalJson. To switch to another implementation, you need to configure it in configConstant as follows:

public void configConstant(Constants me) {
    me.setJsonFactory(new FastJsonFactory());
}
1
2
3

The above configuration switches the system default from JFinalJson to FastJson. You can also extend the Json abstract class and JsonFactory to implement a custom Json implementation.

Suppose you have extended your own MyJson and MyJsonFactory, then you can switch to your own implementation using the following method:

public void configConstant(Constants me) {
    me.setJsonFactory(new MyJsonFactory());
}
1
2
3

In addition, JFinal officially provides the MixedJson and MixedJsonFactory implementations. This implementation uses JFinalJson for converting to JSON strings and FastJson for parsing back into objects.

If you wish to configure this in a non-web context, you need to use JsonManager. For example:

JsonManager.me().setDefaultJsonFactory(new MixedJsonFactory());
1

You can also configure the format of the Date type after it's converted to JSON:

public void configConstant(Constants me) {
    me.setJsonDatePattern("yyyy-MM-dd");
}
1
2
3

Note: When using MixedJsonFactory, FastJsonFactory, or JacksonFactory, you need to add their dependencies. Specific dependencies will be discussed in the next section.

Last Updated: 9/22/2023, 7:48:43 AM