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

com.braintreepayments.http.serializer.Text Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package com.braintreepayments.http.serializer;

import com.braintreepayments.http.HttpRequest;

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

public class Text implements Serializer {

	@Override
	public String contentType() {
		return "^text\\/.*";
	}

	@Override
	public byte[] encode(HttpRequest request) throws IOException {
		if (request.requestBody() instanceof String) {
			return ((String) request.requestBody()).getBytes();
		} else {
			return request.requestBody().toString().getBytes();
		}
	}

	@Override
	public  T decode(String source, Class cls) throws IOException {
		if (!cls.isAssignableFrom(String.class)) {
			throw new UnsupportedEncodingException("Text class unable to return types other than String");
		}

		return (T) source;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy