mjson
Interface Json.Factory

All Known Implementing Classes:
Json.DefaultFactory
Enclosing class:
Json

public static interface Json.Factory

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 make(Object) method allows you plug-in your own mapping of 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 Json.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 Json.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 Json.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.

Author:
Borislav Iordanov

Method Summary
 Json array()
           
 Json bool(boolean value)
           
 Json make(Object anything)
           
 Json nil()
           
 Json number(Number value)
           
 Json object()
           
 Json string(String value)
           
 

Method Detail

nil

Json nil()

bool

Json bool(boolean value)

string

Json string(String value)

number

Json number(Number value)

object

Json object()

array

Json array()

make

Json make(Object anything)


Copyright © 2012. All Rights Reserved.