This interface defines how Json
instances are constructed. There is a default implementation for each kind of Json
value, but you can provide your own implementation. For example, you might want a different representation of an object than a regular HashMap
. Or you might want string comparison to be case insensitive.
In addition, the {@link #make(Object)} method allows you plug-in your own mappingof arbitrary Java objects to Json
instances. You might want to implement a Java Beans to JSON mapping or any other JSON serialization that makes sense in your project.
To avoid implementing all methods in that interface, you can extend the {@link DefaultFactory}default implementation and simply overwrite the ones you're interested in.
The factory implementation used by the Json
classes is specified simply by calling the {@link #setGlobalFactory(Factory)} method. The factory is a static, global variable by default.If you need different factories in different areas of a single application, you may attach them to different threads of execution using the {@link #attachFactory(Factory)}. Recall a separate copy of static variables is made per ClassLoader, so for example in a web application context, that global factory can be different for each web application (as Java web servers usually use a separate class loader per application). Thread-local factories are really a provision for special cases.
|
|
|
|
|
|
|
|