Skip to content

Commit

Permalink
fix protobuf generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Steinke committed Jul 4, 2024
1 parent 9b6a927 commit eeb839c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
15 changes: 2 additions & 13 deletions router-protobuf/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc

plugins {
id("com.google.protobuf") version "0.8.19"
id("com.google.protobuf") version "0.9.4"
}

repositories {
Expand All @@ -25,12 +22,4 @@ dependencies {
testImplementation("io.mockk:mockk:1.13.11")
testImplementation("org.slf4j:slf4j-simple:2.0.13")
testImplementation("com.jayway.jsonpath:json-path:2.9.0")
}


protobuf {
protoc {
// The artifact spec for the Protobuf Compiler
artifact = "com.google.protobuf:protoc:4.27.2"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ProtoDeserializationHandler : DeserializationHandler {
if (input.contentType() == null) {
false
} else {
MediaType.parse(input.contentType()).let { proto.isCompatibleWith(it) || protoStructuredSuffixWildcard.isCompatibleWith(it) }
MediaType.parse(input.contentType()!!).let { proto.isCompatibleWith(it) || protoStructuredSuffixWildcard.isCompatibleWith(it) }
}

override fun deserialize(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.moia.router.proto

import com.google.common.net.MediaType
import com.google.protobuf.GeneratedMessageV3
import com.google.protobuf.GeneratedMessage
import io.moia.router.SerializationHandler
import isCompatibleWith
import java.util.Base64
Expand All @@ -13,13 +13,13 @@ class ProtoSerializationHandler : SerializationHandler {
override fun supports(
acceptHeader: MediaType,
body: Any,
): Boolean = body is GeneratedMessageV3
): Boolean = body is GeneratedMessage

override fun serialize(
acceptHeader: MediaType,
body: Any,
): String {
val message = body as GeneratedMessageV3
val message = body as GeneratedMessage
return if (json.isCompatibleWith(acceptHeader) || jsonStructuredSuffixWildcard.isCompatibleWith(acceptHeader)) {
ProtoBufUtils.toJsonWithoutWrappers(message)
} else {
Expand Down
4 changes: 4 additions & 0 deletions router-protobuf/src/test/proto/Sample.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ syntax = "proto3";

package io.moia.router.proto.sample;

option java_multiple_files = false;
option java_outer_classname = "SampleOuterClass";
option java_package = "io.moia.router.proto.sample";

import "google/protobuf/wrappers.proto";

message Sample {
Expand Down

0 comments on commit eeb839c

Please sign in to comment.