Skip to content

Commit

Permalink
feat(6178): support enums as integers in jruby
Browse files Browse the repository at this point in the history
  • Loading branch information
MQuy committed Feb 2, 2023
1 parent 9d81de2 commit 1163142
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyO
* @param options [Hash] options for the decoder
* preserve_proto_fieldnames: set true to use original fieldnames (default is to camelCase)
* emit_defaults: set true to emit 0/false values (default is to omit them)
* enums_as_integers: set true to enmit enum values as integer (default is string)
*/
@JRubyMethod(name = "encode_json", required = 1, optional = 1, meta = true)
public static IRubyObject encodeJson(
Expand All @@ -698,6 +699,7 @@ public static IRubyObject encodeJson(

IRubyObject emitDefaults = options.fastARef(runtime.newSymbol("emit_defaults"));
IRubyObject preserveNames = options.fastARef(runtime.newSymbol("preserve_proto_fieldnames"));
IRubyObject enumAsIntegers = options.fastARef(runtime.newSymbol("enums_as_integers"));

if (emitDefaults != null && emitDefaults.isTrue()) {
printer = printer.includingDefaultValueFields();
Expand All @@ -706,6 +708,10 @@ public static IRubyObject encodeJson(
if (preserveNames != null && preserveNames.isTrue()) {
printer = printer.preservingProtoFieldNames();
}

if (enumAsIntegers != null && printingEnumsAsInts.isTrue()) {
printer = printer.printingEnumsAsInts();
}
}
printer =
printer.usingTypeRegistry(
Expand Down

0 comments on commit 1163142

Please sign in to comment.