Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion core/src/main/java/io/confluent/rest/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.confluent.rest;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper;

import org.eclipse.jetty.server.Handler;
Expand Down Expand Up @@ -131,7 +132,9 @@ protected void doStop() throws Exception {
public void configureBaseApplication(Configurable<?> config) {
RestConfig restRestConfig = getConfiguration();

config.register(JacksonMessageBodyProvider.class);
ObjectMapper jsonMapper = getJsonMapper();
JacksonMessageBodyProvider jsonProvider = new JacksonMessageBodyProvider(jsonMapper);
config.register(jsonProvider);
config.register(JsonParseExceptionMapper.class);

config.register(ValidationFeature.class);
Expand All @@ -146,6 +149,16 @@ public T getConfiguration() {
return this.config;
}

/**
* Gets a JSON ObjectMapper to use for (de)serialization of request/response entities. Override
* this to configure the behavior of the serializer. One simple example of customization is to
* set the INDENT_OUTPUT flag to make the output more readable. The default is a default
* Jackson ObjectMapper.
*/
protected ObjectMapper getJsonMapper() {
return new ObjectMapper();
}

/**
* Start the server (creating it if necessary).
* @throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public JacksonMessageBodyProvider() {
setMapper(new ObjectMapper());
}

public JacksonMessageBodyProvider(ObjectMapper mapper) {
setMapper(mapper);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ewen Cheslack-Postava (@ewencp) What is the purpose of the wrapping?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly necessary, I just tend to prefer dependency injection at construction to mutators. We could just as easily change this to a call to setMapper() in Application.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

}

@Override
protected boolean hasMatchingMediaType(MediaType mediaType) {
return super.hasMatchingMediaType(mediaType) ||
Expand Down