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

prerna.util.gson.IQuerySelectorAdapterHelper Maven / Gradle / Ivy

The newest version!
package prerna.util.gson;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

import prerna.query.querystruct.selectors.IQuerySelector;

public interface IQuerySelectorAdapterHelper {

	IQuerySelector readContent(JsonReader in) throws IOException;
	
	public static void writeStringMap(JsonWriter out, Map map) throws IOException {
		if(map == null) {
			out.nullValue();
			return;
		}
		
		out.beginObject();
		for(String key : map.keySet()) {
			out.name(key);
			out.value(map.get(key));
		}
		out.endObject();
	}
	
	public static Map readStringMap(JsonReader in) throws IOException {
		if(in.peek() == JsonToken.NULL) {
			return null;
		}
		
		Map values = new HashMap();
		
		in.beginObject();
		while(in.hasNext()) {
			String key = in.nextName();
			String value = in.nextString();
			values.put(key, value);
		}
		in.endObject();
		
		return values;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy