@@ -229,6 +229,52 @@ public GlossariesMatchesValue deserialize(JsonElement json, Type typeOfT, JsonDe
229229 }
230230 }
231231
232+ @ JsonAdapter (ProfanitiesValueDeserializer .class )
233+ public static class ProfanitiesValue {
234+ private final ProfanityDetectResult single ;
235+ private final List <ProfanityDetectResult > list ;
236+
237+ public ProfanitiesValue (ProfanityDetectResult single ) {
238+ this .single = single ;
239+ this .list = null ;
240+ }
241+
242+ public ProfanitiesValue (List <ProfanityDetectResult > list ) {
243+ this .single = null ;
244+ this .list = list ;
245+ }
246+
247+ public ProfanityDetectResult getSingle () {
248+ return single ;
249+ }
250+
251+ public List <ProfanityDetectResult > getList () {
252+ return list ;
253+ }
254+
255+ @ Override
256+ public String toString () {
257+ if (single != null ) return single .toString ();
258+ if (list != null ) return list .toString ();
259+ return null ;
260+ }
261+ }
262+
263+ public static class ProfanitiesValueDeserializer implements JsonDeserializer <ProfanitiesValue > {
264+ @ Override
265+ public ProfanitiesValue deserialize (JsonElement json , Type typeOfT , JsonDeserializationContext context ) throws JsonParseException {
266+ if (json .isJsonObject ()) {
267+ ProfanityDetectResult single = context .deserialize (json , ProfanityDetectResult .class );
268+ return new ProfanitiesValue (single );
269+ } else if (json .isJsonArray ()) {
270+ Type listType = new TypeToken <List <ProfanityDetectResult >>(){}.getType ();
271+ List <ProfanityDetectResult > list = context .deserialize (json , listType );
272+ return new ProfanitiesValue (list );
273+ }
274+ throw new JsonParseException ("Expected JSON object or array for profanities" );
275+ }
276+ }
277+
232278 private final String contentType ;
233279 private final String sourceLanguage ;
234280 private final List <String > adaptedTo ;
@@ -237,6 +283,7 @@ public GlossariesMatchesValue deserialize(JsonElement json, Type typeOfT, JsonDe
237283 private final Value translation ;
238284 private final AdaptedToMatchesValue adaptedToMatches ;
239285 private final GlossariesMatchesValue glossariesMatches ;
286+ private final ProfanitiesValue profanities ;
240287
241288 public TextResult (String contentType , String sourceLanguage , String translation , String [] adaptedTo , String [] glossaries ) {
242289 this .contentType = contentType ;
@@ -247,6 +294,7 @@ public TextResult(String contentType, String sourceLanguage, String translation,
247294 this .translation = new Value (translation );
248295 this .adaptedToMatches = null ;
249296 this .glossariesMatches = null ;
297+ this .profanities = null ;
250298 }
251299
252300 public TextResult (String contentType , String sourceLanguage , String [] translation , String [] adaptedTo , String [] glossaries ) {
@@ -258,6 +306,7 @@ public TextResult(String contentType, String sourceLanguage, String[] translatio
258306 this .translation = new Value (translation );
259307 this .adaptedToMatches = null ;
260308 this .glossariesMatches = null ;
309+ this .profanities = null ;
261310 }
262311
263312 public TextResult (String contentType , String sourceLanguage , TextBlock [] translation , String [] adaptedTo , String [] glossaries ) {
@@ -269,6 +318,7 @@ public TextResult(String contentType, String sourceLanguage, TextBlock[] transla
269318 this .translation = new Value (translation );
270319 this .adaptedToMatches = null ;
271320 this .glossariesMatches = null ;
321+ this .profanities = null ;
272322 }
273323
274324
@@ -316,6 +366,14 @@ public List<List<NGGlossaryMatch>> getGlossariesMatchesList() {
316366 return glossariesMatches != null ? glossariesMatches .getMatchesList () : null ;
317367 }
318368
369+ public ProfanityDetectResult getProfanities () {
370+ return profanities != null ? profanities .getSingle () : null ;
371+ }
372+
373+ public List <ProfanityDetectResult > getProfanitiesList () {
374+ return profanities != null ? profanities .getList () : null ;
375+ }
376+
319377 @ Override
320378 public String toString () {
321379 return this .translation .toString ();
0 commit comments