Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds protocol buffer support to Jackson via 3rd party module #112

Merged
merged 9 commits into from
Dec 18, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
#### Bug fixes
- Topics shown on brokers now include "internal" topics.
- Generated consumer client.id shortened.
- [#111](https://github.com/SourceLabOrg/kafka-webview/issues/111) Add ProtocolBuffer support to Jackson via third party module.

#### Internal Dependency Updates
- Upgrade from Spring Boot 2.0.5 to 2.0.7
Expand Down
40 changes: 40 additions & 0 deletions kafka-webview-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,38 @@
<optional>true</optional>
</dependency>

<!-- Jackson support for protocol buffers -->
<dependency>
<groupId>com.hubspot.jackson</groupId>
<artifactId>jackson-datatype-protobuf</artifactId>
<version>0.9.10-jackson2.9-proto3</version>
<exclusions>
<!-- exclude out-dated dependency -->
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Explicitly include updated guava version for jackson protobuf module -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>

<!-- For tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -179,6 +211,14 @@
<scope>test</scope>
</dependency>

<!-- Test case for validating protocol buffer support in Jackson -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.6.1</version>
<scope>test</scope>
</dependency>

<!-- Embedded LDAP server for tests -->
<dependency>
<groupId>org.zapodot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.sourcelab.kafka.webview.ui.configuration;

import com.hubspot.jackson.datatype.protobuf.ProtobufModule;
import org.apache.kafka.common.serialization.Deserializer;
import org.sourcelab.kafka.webview.ui.manager.encryption.SecretManager;
import org.sourcelab.kafka.webview.ui.manager.kafka.KafkaAdminFactory;
Expand All @@ -33,6 +34,7 @@
import org.sourcelab.kafka.webview.ui.manager.plugin.PluginFactory;
import org.sourcelab.kafka.webview.ui.manager.plugin.UploadManager;
import org.sourcelab.kafka.webview.ui.plugin.filter.RecordFilter;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -112,6 +114,18 @@ public KafkaOperationsFactory getKafkaOperationsFactory(final AppProperties appP
);
}

/**
* Customize the jackson object map builder.
* @return Jackson2ObjectMapperBuilderCustomizer instance.
*/
@Bean
public Jackson2ObjectMapperBuilderCustomizer addCustomBigDecimalDeserialization() {
return jacksonObjectMapperBuilder -> {
// Register custom protocol buffer serializer as protocol buffers is a common serialization format.
jacksonObjectMapperBuilder.modulesToInstall(new ProtobufModule());
};
}

/**
* For creating instances of AdminClient.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.io.IOException;

/**
* Uses object's toString() method to serialize.
* Attempts to serialize using Jackson, if that fails, falls back to using toString.
*/
public class ToStringSerializer extends JsonSerializer<Object> {
@Override
Expand All @@ -52,8 +52,6 @@ public void serialize(
serializer.serialize(value, gen, serializers);
return;
}

// Fall back to using toString()
gen.writeString(value.toString());
}
}
Loading