File tree Expand file tree Collapse file tree 5 files changed +19
-16
lines changed
main/kotlin/io/moia/router/proto Expand file tree Collapse file tree 5 files changed +19
-16
lines changed Original file line number Diff line number Diff line change 1- import com.google.protobuf.gradle.protobuf
2- import com.google.protobuf.gradle.protoc
3-
41plugins {
5- id(" com.google.protobuf" ) version " 0.8.19 "
2+ id(" com.google.protobuf" ) version " 0.9.4 "
63}
74
85repositories {
96 mavenCentral()
107}
118
9+ val protoVersion = " 4.27.2"
10+
1211dependencies {
1312 implementation(kotlin(" stdlib" ))
1413 implementation(kotlin(" reflect" ))
1514
1615 implementation(" org.slf4j:slf4j-api:2.0.13" )
17- api(" com.google.protobuf:protobuf-java:3.25.3 " )
18- api(" com.google.protobuf:protobuf-java-util:3.25.3 " )
16+ api(" com.google.protobuf:protobuf-java:$protoVersion " )
17+ api(" com.google.protobuf:protobuf-java-util:$protoVersion " )
1918 implementation(" com.google.guava:guava:33.2.1-jre" )
2019 api(project(" :router" ))
2120
@@ -27,10 +26,10 @@ dependencies {
2726 testImplementation(" com.jayway.jsonpath:json-path:2.9.0" )
2827}
2928
30-
3129protobuf {
30+ // Configure the protoc executable
3231 protoc {
33- // The artifact spec for the Protobuf Compiler
34- artifact = " com.google.protobuf:protoc:3.25.3 "
32+ // Download from repositories
33+ artifact = " com.google.protobuf:protoc:$protoVersion "
3534 }
3635}
Original file line number Diff line number Diff line change @@ -4,12 +4,12 @@ import com.fasterxml.jackson.databind.JsonNode
44import com.fasterxml.jackson.databind.node.ArrayNode
55import com.fasterxml.jackson.databind.node.ObjectNode
66import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7- import com.google.protobuf.GeneratedMessageV3
7+ import com.google.protobuf.GeneratedMessage
88import com.google.protobuf.util.JsonFormat
99
1010object ProtoBufUtils {
11- fun toJsonWithoutWrappers (proto : GeneratedMessageV3 ): String {
12- val message = JsonFormat .printer().omittingInsignificantWhitespace().includingDefaultValueFields ().print (proto)
11+ fun toJsonWithoutWrappers (proto : GeneratedMessage ): String {
12+ val message = JsonFormat .printer().omittingInsignificantWhitespace().alwaysPrintFieldsWithNoPresence ().print (proto)
1313 return removeWrapperObjects(message)
1414 }
1515
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class ProtoDeserializationHandler : DeserializationHandler {
1919 if (input.contentType() == null ) {
2020 false
2121 } else {
22- MediaType .parse(input.contentType()).let { proto.isCompatibleWith(it) || protoStructuredSuffixWildcard.isCompatibleWith(it) }
22+ MediaType .parse(input.contentType()!! ).let { proto.isCompatibleWith(it) || protoStructuredSuffixWildcard.isCompatibleWith(it) }
2323 }
2424
2525 override fun deserialize (
Original file line number Diff line number Diff line change 11package io.moia.router.proto
22
33import com.google.common.net.MediaType
4- import com.google.protobuf.GeneratedMessageV3
4+ import com.google.protobuf.GeneratedMessage
55import io.moia.router.SerializationHandler
66import isCompatibleWith
77import java.util.Base64
@@ -13,13 +13,13 @@ class ProtoSerializationHandler : SerializationHandler {
1313 override fun supports (
1414 acceptHeader : MediaType ,
1515 body : Any ,
16- ): Boolean = body is GeneratedMessageV3
16+ ): Boolean = body is GeneratedMessage
1717
1818 override fun serialize (
1919 acceptHeader : MediaType ,
2020 body : Any ,
2121 ): String {
22- val message = body as GeneratedMessageV3
22+ val message = body as GeneratedMessage
2323 return if (json.isCompatibleWith(acceptHeader) || jsonStructuredSuffixWildcard.isCompatibleWith(acceptHeader)) {
2424 ProtoBufUtils .toJsonWithoutWrappers(message)
2525 } else {
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ syntax = "proto3";
22
33package io.moia.router.proto.sample ;
44
5+ option java_multiple_files = false ;
6+ option java_outer_classname = "SampleOuterClass" ;
7+ option java_package = "io.moia.router.proto.sample" ;
8+
59import "google/protobuf/wrappers.proto" ;
610
711message Sample {
You can’t perform that action at this time.
0 commit comments