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

com.jd.httpservice.converters.JsonBodyConverter Maven / Gradle / Ivy

There is a newer version: 2.1.4.RELEASE
Show newest version
package com.jd.httpservice.converters;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

import com.jd.httpservice.HttpServiceConsts;
import com.jd.httpservice.RequestBodyConverter;

import utils.serialize.json.JSONSerializeUtils;

public class JsonBodyConverter implements RequestBodyConverter {
	
	private Class dataType;
	
	public JsonBodyConverter(Class dataType) {
		this.dataType = dataType;
	}

	@Override
	public void write(Object param, OutputStream out) throws IOException{
		String jsonString = JSONSerializeUtils.serializeToJSON(param, dataType);
		try {
			out.write(jsonString.getBytes(HttpServiceConsts.CHARSET));
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy