Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
This file is part of Niowire. Niowire is free software: you can redistribute it and/or modify it under the terms of the Lesser GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Niowire is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public License for more details. You should have received a copy of the Lesser GNU General Public License along with Niowire. If not, see <>.
package io.niowire.serializer;
This serializer expects each line to be a JSON object, which it will deserialize into a Map. We are using google Gson to serialize/deserialize objects.

Trent Houliston
public class JsonSerializer extends LineSerializer
	//Our gson instance
Deserializes the passed string into a LinkedHashMap object treating the input as a JSON object

str the string to use as the JSON object
a LinkedHashMap containing the mapping of the JSON Object
		//Work out if we are deserializing an array or object
		switch (str.charAt(0))
			//For an array
			case '[':
				return .fromJson(strArrayList.class);
			//For an object (map)
			case '{':
				return .fromJson(strLinkedHashMap.class);

Serializes the past object into a JSON string format

obj the java object which we will serialize into JSON
a string representation of the passed object in JSON
		return .toJson(obj.getData());
New to GrepCode? Check out our FAQ X