All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.venky.swf.extensions.JSONRegistrar Maven / Gradle / Ivy

There is a newer version: 2.11
Show newest version
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);
					}
				});
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy