@@ -13,15 +13,15 @@ and `java.util.Set`. In order to handle arbitrary implementations, idiosyncratic
1313implementating classes are ignored and all implementations are assigned the least common nature of lists and sets. That is,
1414an implementation of ` java.util.List ` is considered to be an ordered sequence and is translated to a protobuf
1515message type of the form
16- ```
16+ ``` protobuf
1717 message java_util___ArrayList16 {
1818 string classname = 1;
1919 repeated int32 data = 2;
2020 }
2121```
2222and an implementation of ` java.util.Set ` is considered to be an unordered collection and is translated to a
2323protobuf message type of the form
24- ```
24+ ``` protobuf
2525 message java_util___HashSet3 {
2626 string classname = 1;
2727 repeated string data = 2;
@@ -40,7 +40,7 @@ a workaround. The important thing is to define a protobuf message whose repeated
4040` java_util___ArrayList16 ` . That would be a reasonable representation of ` ArrayList<Integer> ` . Similarly, ` java_util___HashSet3 `
4141would be a reasonable representation of ` HashSet<String> ` . The ` JavaToProtobufGenerator ` class in the
4242[ grpc-bridge] ( https://github.com/resteasy/resteasy-grpc ) module generates the protobuf messages and decorates them as follows:
43- ```
43+ ``` java
4444 // List: java.util.ArrayList<java.lang.Integer>
4545 message java_util___ArrayList16 {
4646 string classname = 1 ;
@@ -56,7 +56,7 @@ would be a reasonable representation of `HashSet<String>`. The `JavaToProtobufGe
5656 }
5757```
5858These are two simple examples. Consider something a little more complicated: ` java.util.ArrayList<java.util.HashSet<java.lang.String>> ` :
59- ```
59+ ``` java
6060 // List: java.util.ArrayList<java.util.HashSet<java.lang.String>>
6161 message java_util___ArrayList14 {
6262 string classname = 1 ;
@@ -70,7 +70,7 @@ field in `java_util___ArrayList14` is of type `java_util___HashSet3`.
7070A complication arises in the form of type variables and wildcards. The solution adopted in resteasy-grpc is to map unassigned
7171type variables and wildcards to ` java.lang.Object ` , which makes sense, since they can take any types at runtime. The protobuf
7272analog to ` java.lang.Object ` is ` google.protobuf.Any ` , which is defined
73- ```
73+ ``` protobuf
7474 message Any {
7575 string type_url = 1;
7676 bytes value = 2;
@@ -81,7 +81,7 @@ package declared in the .proto file. The value field has built-in type bytes, w
8181of bytes no longer than 2^32", according to https://developers.google.com/protocol-buffers/docs/proto3 .
8282
8383Suppose we have the Jakarta REST resource methods
84- ```
84+ ``` java
8585 package x.y ;
8686
8787 @GET
@@ -110,13 +110,13 @@ Suppose we have the Jakarta REST resource methods
110110 }
111111```
112112where x.y.Grimble is
113- ```
113+ ``` java
114114 public class Grimble <T> {
115115 T t;
116116 }
117117```
118118` JavaToProtobufGenerator ` would create the rpc and message definitions
119- ```
119+ ``` protobuf
120120 // p/grimble/raw x_y___Grimble google.protobuf.Empty GET sync
121121 rpc gr_raw (GeneralEntityMessage) returns (GeneralReturnMessage);
122122
@@ -155,7 +155,7 @@ where x.y.Grimble is
155155```
156156The details about the rpc comments are described elsewhere ([ gRPC Bridge Project: User Guide] ( https://resteasy.dev/docs/grpc/ ) ),
157157but here it's enough to know that the rpc definition
158- ```
158+ ``` protobuf
159159 // p/grimble/variable x_y___Grimble18 google.protobuf.Empty GET sync
160160 rpc gr_variable (GeneralEntityMessage) returns (GeneralReturnMessage);
161161```
@@ -175,15 +175,15 @@ type `google.protobuf.Any`, which, as discussed above, represents an arbitrary t
175175` of java.lang.Object ` .
176176
177177The discussion about generic types and type variables applies to lists and sets. For example,
178- ```
178+ ``` java
179179 @Path (" arraylist/hashset/wildcard" )
180180 @POST
181181 public ArrayList<HashSet<?> > arraylistHashsetTest2(ArrayList<HashSet<?> > l) {
182182 return l;
183183 }
184184```
185185gives rise to
186- ```
186+ ``` java
187187 // List: java.util.ArrayList<java.util.HashSet<java.lang.Object>>
188188 message java_util___ArrayList13 {
189189 string classname = 1 ;
@@ -202,7 +202,7 @@ gives rise to
202202Here we' ll discuss a gRPC client intending to communicate with a Jakarta REST server. The subject is covered in detail in
203203[gRPC Bridge Project: User Guide](https://resteasy.dev/docs/grpc/), but here we will look at sending and receiving
204204`Collection`s. For example, consider the resource method
205- ```
205+ ```java
206206 @GET
207207 @Path("arraylist/integer")
208208 public ArrayList<?> listArray0(ArrayList<Integer> list) {
@@ -212,15 +212,15 @@ Here we'll discuss a gRPC client intending to communicate with a Jakarta REST se
212212We' ve seen that `java.util.ArrayList<java.lang. Integer > ` translates to javabuf class `java_util___ArrayList16`. So the client
213213has to create an instance of `java_util___ArrayList16` to send to the server. There are two possible strategies. One is to
214214work in the javabuf world:
215- ```
215+ ```java
216216 java_util___ArrayList16. Builder juaBuilder = java_util___ArrayList16. newBuilder();
217217 juaBuilder. setClassname(" java.util.ArrayList" );
218218 juaBuilder. addData(3 );
219219 juaBuilder. addData(7 );
220220 java_util___ArrayList16 jua = juaBuilder. build();
221221```
222222Alternatively , one could create an `ArrayList ` and translate it to an `java_util___ArrayList16`:
223- ```
223+ ```java
224224 ArrayList<Integer > list = new ArrayList<Integer > ();
225225 list. add(3 );
226226 list. add(7 );
@@ -229,18 +229,18 @@ Alternatively, one could create an `ArrayList` and translate it to an `java_util
229229```
230230where `translator` is an instance of `dev.resteasy.grpc.bridge.runtime.protobuf. JavabufTranslator `.
231231The next step is to build a `GeneralEntityMessage `:
232- ```
232+ ```java
233233 GeneralEntityMessage . Builder gemBuilder = GeneralEntityMessage . newBuilder();
234234 gemBuilder. setJavaUtilArrayList16Field(gemBuilder. build());
235235```
236236Then the remote method can be invoked:
237- ```
237+ ```java
238238 GeneralReturnMessage response = stub. listArray0(gem);
239239```
240240where `stub` is the client side representative of the server methods.
241241Finally , the result can be extracted from the `GeneralReturnMessage `. Note that `listArray0` returns
242242an instance of `ArrayList<?> `, which translates to javabuf class
243- ```
243+ ```java
244244 // List: java.util.ArrayList<java.lang.Object>
245245 message java_util___ArrayList17 {
246246 string classname = 1 ;
@@ -249,11 +249,11 @@ an instance of `ArrayList<?>`, which translates to javabuf class
249249 }
250250```
251251This complicates things a bit since we have to extract the returned list from an `Any `.
252- ```
252+ ```java
253253 java_util___ArrayList17 result = response. getJavaUtilArrayList17Field();
254254 Any any = response. getAnyField();
255255 Message result = any. unpack((Class ) Utility . extractClassFromAny(any, translator));
256256 list = (ArrayList<Object > ) translator. translateFromJavabuf(result);
257257```
258258### Maps
259- Stay tuned for the next release, which which implementations of ` java.util.Map ` will be treated in a similar way .
259+ Stay tuned for the next release, in which implementations of `java.util. Map ` will be treated similarly .
0 commit comments