com.venky.swf.extensions.JSONRegistrar Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swf-db-io-json Show documentation
Show all versions of swf-db-io-json Show documentation
Succinct Web Framework JSON plugin
package com.venky.swf.extensions;
import java.io.InputStream;
import org.json.simple.JSONObject;
import com.venky.swf.db.annotations.column.ui.mimes.MimeType;
import com.venky.swf.db.model.Model;
import com.venky.swf.db.model.io.ModelIOFactory;
import com.venky.swf.db.model.io.ModelReader;
import com.venky.swf.db.model.io.ModelReaderFactory;
import com.venky.swf.db.model.io.ModelWriter;
import com.venky.swf.db.model.io.ModelWriterFactory;
import com.venky.swf.db.model.io.json.JSONModelReader;
import com.venky.swf.db.model.io.json.JSONModelWriter;
import com.venky.swf.integration.FormatHelper;
import com.venky.swf.integration.FormatHelperBuilder;
import com.venky.swf.integration.JSON;
public class JSONRegistrar {
static {
FormatHelper.registerFormat(MimeType.APPLICATION_JSON,
JSONObject.class, new FormatHelperBuilder() {
public FormatHelper constructFormatHelper(
InputStream in) {
return new JSON(in);
}
public FormatHelper constructFormatHelper(
String root, boolean isPlural) {
return new JSON(root, isPlural);
}
public FormatHelper constructFormatHelper(
JSONObject rootElement) {
return new JSON(rootElement);
}
});
ModelIOFactory.registerIOFactories(JSONObject.class,
new ModelReaderFactory() {
public ModelReader createModelReader(
Class modelClass) {
return new JSONModelReader(modelClass);
}
}, new ModelWriterFactory() {
public ModelWriter createModelWriter(
Class modelClass) {
return new JSONModelWriter(modelClass);
}
});
}
}