com.braintreepayments.http.serializer.Text Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of braintreehttp Show documentation
Show all versions of braintreehttp Show documentation
This is Braintree's generic http library for generated SDKs
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;
}
}