@@ -91,7 +91,8 @@ public static Printer printer() {
91
91
/* preservingProtoFieldNames */ false ,
92
92
/* omittingInsignificantWhitespace */ false ,
93
93
/* printingEnumsAsInts */ false ,
94
- /* sortingMapKeys */ false );
94
+ /* sortingMapKeys */ false ,
95
+ /* unsafeDisableCodepointsForHtmlSymbols */ false );
95
96
}
96
97
97
98
private enum ShouldPrintDefaults {
@@ -114,6 +115,7 @@ public static class Printer {
114
115
private final boolean omittingInsignificantWhitespace ;
115
116
private final boolean printingEnumsAsInts ;
116
117
private final boolean sortingMapKeys ;
118
+ private final boolean unsafeDisableCodepointsForHtmlSymbols ;
117
119
118
120
private Printer (
119
121
com .google .protobuf .TypeRegistry registry ,
@@ -123,7 +125,8 @@ private Printer(
123
125
boolean preservingProtoFieldNames ,
124
126
boolean omittingInsignificantWhitespace ,
125
127
boolean printingEnumsAsInts ,
126
- boolean sortingMapKeys ) {
128
+ boolean sortingMapKeys ,
129
+ boolean unsafeDisableCodepointsForHtmlSymbols ) {
127
130
this .registry = registry ;
128
131
this .oldRegistry = oldRegistry ;
129
132
this .shouldPrintDefaults = shouldOutputDefaults ;
@@ -132,6 +135,7 @@ private Printer(
132
135
this .omittingInsignificantWhitespace = omittingInsignificantWhitespace ;
133
136
this .printingEnumsAsInts = printingEnumsAsInts ;
134
137
this .sortingMapKeys = sortingMapKeys ;
138
+ this .unsafeDisableCodepointsForHtmlSymbols = unsafeDisableCodepointsForHtmlSymbols ;
135
139
}
136
140
137
141
/**
@@ -153,7 +157,8 @@ public Printer usingTypeRegistry(TypeRegistry oldRegistry) {
153
157
preservingProtoFieldNames ,
154
158
omittingInsignificantWhitespace ,
155
159
printingEnumsAsInts ,
156
- sortingMapKeys );
160
+ sortingMapKeys ,
161
+ unsafeDisableCodepointsForHtmlSymbols );
157
162
}
158
163
159
164
/**
@@ -175,7 +180,8 @@ public Printer usingTypeRegistry(com.google.protobuf.TypeRegistry registry) {
175
180
preservingProtoFieldNames ,
176
181
omittingInsignificantWhitespace ,
177
182
printingEnumsAsInts ,
178
- sortingMapKeys );
183
+ sortingMapKeys ,
184
+ unsafeDisableCodepointsForHtmlSymbols );
179
185
}
180
186
181
187
/**
@@ -204,7 +210,8 @@ public Printer includingDefaultValueFields() {
204
210
preservingProtoFieldNames ,
205
211
omittingInsignificantWhitespace ,
206
212
printingEnumsAsInts ,
207
- sortingMapKeys );
213
+ sortingMapKeys ,
214
+ unsafeDisableCodepointsForHtmlSymbols );
208
215
}
209
216
210
217
/**
@@ -232,7 +239,8 @@ public Printer includingDefaultValueFields(Set<FieldDescriptor> fieldsToAlwaysOu
232
239
preservingProtoFieldNames ,
233
240
omittingInsignificantWhitespace ,
234
241
printingEnumsAsInts ,
235
- sortingMapKeys );
242
+ sortingMapKeys ,
243
+ unsafeDisableCodepointsForHtmlSymbols );
236
244
}
237
245
238
246
/**
@@ -253,7 +261,8 @@ public Printer alwaysPrintFieldsWithNoPresence() {
253
261
preservingProtoFieldNames ,
254
262
omittingInsignificantWhitespace ,
255
263
printingEnumsAsInts ,
256
- sortingMapKeys );
264
+ sortingMapKeys ,
265
+ unsafeDisableCodepointsForHtmlSymbols );
257
266
}
258
267
259
268
/**
@@ -270,7 +279,8 @@ public Printer printingEnumsAsInts() {
270
279
preservingProtoFieldNames ,
271
280
omittingInsignificantWhitespace ,
272
281
true ,
273
- sortingMapKeys );
282
+ sortingMapKeys ,
283
+ unsafeDisableCodepointsForHtmlSymbols );
274
284
}
275
285
276
286
private void checkUnsetPrintingEnumsAsInts () {
@@ -294,7 +304,8 @@ public Printer preservingProtoFieldNames() {
294
304
true ,
295
305
omittingInsignificantWhitespace ,
296
306
printingEnumsAsInts ,
297
- sortingMapKeys );
307
+ sortingMapKeys ,
308
+ unsafeDisableCodepointsForHtmlSymbols );
298
309
}
299
310
300
311
@@ -323,7 +334,8 @@ public Printer omittingInsignificantWhitespace() {
323
334
preservingProtoFieldNames ,
324
335
true ,
325
336
printingEnumsAsInts ,
326
- sortingMapKeys );
337
+ sortingMapKeys ,
338
+ unsafeDisableCodepointsForHtmlSymbols );
327
339
}
328
340
329
341
/**
@@ -346,7 +358,8 @@ public Printer sortingMapKeys() {
346
358
preservingProtoFieldNames ,
347
359
omittingInsignificantWhitespace ,
348
360
printingEnumsAsInts ,
349
- true );
361
+ true ,
362
+ unsafeDisableCodepointsForHtmlSymbols );
350
363
}
351
364
352
365
/**
@@ -368,7 +381,8 @@ public void appendTo(MessageOrBuilder message, Appendable output) throws IOExcep
368
381
output ,
369
382
omittingInsignificantWhitespace ,
370
383
printingEnumsAsInts ,
371
- sortingMapKeys )
384
+ sortingMapKeys ,
385
+ unsafeDisableCodepointsForHtmlSymbols )
372
386
.print (message );
373
387
}
374
388
@@ -726,6 +740,8 @@ private static final class PrinterImpl {
726
740
727
741
private static class GsonHolder {
728
742
private static final Gson DEFAULT_GSON = new GsonBuilder ().create ();
743
+ private static final Gson GSON_WITHOUT_HTML_ESCAPING =
744
+ new GsonBuilder ().disableHtmlEscaping ().create ();
729
745
}
730
746
731
747
PrinterImpl (
@@ -737,15 +753,19 @@ private static class GsonHolder {
737
753
Appendable jsonOutput ,
738
754
boolean omittingInsignificantWhitespace ,
739
755
boolean printingEnumsAsInts ,
740
- boolean sortingMapKeys ) {
756
+ boolean sortingMapKeys ,
757
+ boolean unsafeDisableCodepointsForHtmlSymbols ) {
741
758
this .registry = registry ;
742
759
this .oldRegistry = oldRegistry ;
743
760
this .shouldPrintDefaults = shouldPrintDefaults ;
744
761
this .includingDefaultValueFields = includingDefaultValueFields ;
745
762
this .preservingProtoFieldNames = preservingProtoFieldNames ;
746
763
this .printingEnumsAsInts = printingEnumsAsInts ;
747
764
this .sortingMapKeys = sortingMapKeys ;
748
- this .gson = GsonHolder .DEFAULT_GSON ;
765
+ this .gson =
766
+ unsafeDisableCodepointsForHtmlSymbols
767
+ ? GsonHolder .GSON_WITHOUT_HTML_ESCAPING
768
+ : GsonHolder .DEFAULT_GSON ;
749
769
// json format related properties, determined by printerType
750
770
if (omittingInsignificantWhitespace ) {
751
771
this .generator = new CompactTextGenerator (jsonOutput );
0 commit comments