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

org.github.evenjn.json.JsonDecoderBlueprint Maven / Gradle / Ivy

The newest version!
/**
 *
 * Copyright 2017 Marco Trevisan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package org.github.evenjn.json;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;

import org.github.evenjn.lang.Rook;
import org.github.evenjn.yarn.RingFunction;

import com.google.gson.Gson;


public class JsonDecoderBlueprint {

	public RingFunction build( ) {
		Charset local_cs = cs;
		Class local_class_of_t = class_of_t;
		
		return new RingFunction( ) {

			@Override
			public T apply( Rook rook, InputStream is ) {
				Reader reader = rook.hook( new InputStreamReader( is, local_cs ) );
				return new Gson( ).fromJson( reader, local_class_of_t );
			}
		} ;
	}
	
	private Charset cs = Charset.forName( "UTF-8" );

	public JsonDecoderBlueprint setCharset( Charset cs ) {
		this.cs = cs;
		return this;
	}
	
	public JsonDecoderBlueprint(Class class_of_t) {
		this.class_of_t = class_of_t;
	}
	
	private Class class_of_t;

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy