pippo
pippo copied to clipboard
Binary render type with byte array
It would be good if Pippo can render binary type using byte[]
. I'm intend to use for rendering Protobuf. Currently is impossible because ContentTypeEngine.toString(Object object)
only allow String type.
public interface ContentTypeEngine {
void init(Application application);
String getContentType();
String toString(Object object);
<T> T fromString(String content, Class<T> classOfT);
}
I will investigate your request. If you have some ideas please let me know.
I started to work on this feature.
The new signature of ContentTypeEngine
is:
public interface ContentTypeEngine {
void init(Application application);
String getContentType();
<T> T readObject(Class<T> classOfT, Request request);
void writeObject(Object object, Response response);
}
So, the old toString
method becomes writeObject
and the old fromString
method becomes readObject
.
The modifications are trivial. For example instead of send(contentTypeEngine.toString(object))
(https://github.com/decebals/pippo/blob/master/pippo-core/src/main/java/ro/pippo/core/Response.java#L923) we have contentTypeEngine.writeObject(object, this)
.
You should remark that in readObject and writeObject you have full access to Request and Response (maybe some implementations want to deal with headers).
The actual implementations of ContentTypeEngine
s are text based. In this case the implementations of readObject and writeObject are trivial, based on request.getBody()
and response.send(object.toString())
.
I see a single problem for now. PippoRule
uses the actual toString and fromString for RestAssured's ObjectMapper (https://github.com/decebals/pippo/blob/master/pippo-test/src/main/java/ro/pippo/test/PippoRule.java#L100) and I don't know for the moment how to resolve this mismatch (I don't have a Request, Response).
Any idea, any advice or feedback is welcome.
Any news on this, so far?
Just realized Jetty doesn't support partial requests, so I was left with implementing that myself
EDIT: It's currently possible to avoid the issue by registering a custom content type || outputting to the HttpServletOutput directly
@lvivtotoro
I didn't finish my work on this feature because I didn't find a solution for the problem with PippoRule
. I think that I can push my work on GitHub, maybe someone will find a solution.