openrtb-core/src/main/java/com/google/openrtb/json/AbstractOpenRtbJsonWriter.java
@SuppressWarnings("unchecked")
  protected final <EM extends ExtendableMessage<EM>>
  void writeExtensions(EM msg, JsonGenerator gen) throws IOException {
    boolean openExt = false;

    for (Map.Entry<FieldDescriptor, Object> field : msg.getAllFields().entrySet()) {
      FieldDescriptor fd = field.getKey();
      if (fd.isExtension()) {
        if (fd.isRepeated()) {
          List<Object> extValue = (List<Object>) field.getValue();
          if (!extValue.isEmpty()) {
            OpenRtbJsonExtWriter<Object> extWriter =
                factory.getWriter(msg.getClass(), extValue.get(0).getClass(), fd.getName());
            if (extWriter != null) {
              openExt = openExt(gen, openExt);
              extWriter.writeRepeated(extValue, gen);
            }
          }
        } else {
          Object extValue = field.getValue();
          OpenRtbJsonExtWriter<Object> extWriter =
              factory.getWriter(msg.getClass(), extValue.getClass(), fd.getName());
          if (extWriter != null) {
            openExt = openExt(gen, openExt);
            extWriter.writeSingle(extValue, gen);
          }
        }
      }
    }

    if (openExt) {
      gen.writeEndObject();
    }
  }
@SuppressWarnings("unchecked")
  protected final <EM extends ExtendableMessage<EM>>
  void writeExtensions(EM msg, JsonGenerator gen) throws IOException {
    boolean openExt = false;

    for (Map.Entry<FieldDescriptor, Object> field : msg.getAllFields().entrySet()) {
      FieldDescriptor fd = field.getKey();
      if (fd.isExtension()) {
        if (fd.isRepeated()) {
          List<Object> extValue = (List<Object>) field.getValue();
          if (!extValue.isEmpty()) {
            OpenRtbJsonExtWriter<Object> extWriter =
                factory.getWriter(msg.getClass(), extValue.get(0).getClass(), fd.getName());
            if (extWriter != null) {
              openExt = openExt(gen, openExt);
              extWriter.writeRepeated(extValue, gen);
            }
          }
        } else {
          Object extValue = field.getValue();
          OpenRtbJsonExtWriter<Object> extWriter =
              factory.getWriter(msg.getClass(), extValue.getClass(), fd.getName());
          if (extWriter != null) {
            openExt = openExt(gen, openExt);
            extWriter.writeSingle(extValue, gen);
          }
        }
      }
    }

    if (openExt) {
      gen.writeEndObject();
    }
  }
@ SuppressWarnings ( "unchecked" ) protected final < EM extends ExtendableMessage < EM > > void writeExtensions ( EM msg , JsonGenerator gen ) throws IOException { boolean openExt = false ; for ( Map . Entry < FieldDescriptor , Object > field : msg . getAllFields ( ) . entrySet ( ) ) { FieldDescriptor fd = field . getKey ( ) ; if ( fd . isExtension ( ) ) { if ( fd . isRepeated ( ) ) { List < Object > extValue = ( List < Object > ) field . getValue ( ) ; if ( ! extValue . isEmpty ( ) ) { OpenRtbJsonExtWriter < Object > extWriter = factory . getWriter ( msg . getClass ( ) , extValue . get ( 0 ) . getClass ( ) , fd . getName ( ) ) ; if ( extWriter != null ) { openExt = openExt ( gen , openExt ) ; extWriter . writeRepeated ( extValue , gen ) ; } } } else { Object extValue = field . getValue ( ) ; OpenRtbJsonExtWriter < Object > extWriter = factory . getWriter ( msg . getClass ( ) , extValue . getClass ( ) , fd . getName ( ) ) ; if ( extWriter != null ) { openExt = openExt ( gen , openExt ) ; extWriter . writeSingle ( extValue , gen ) ; } } } } if ( openExt ) { gen . writeEndObject ( ) ; } }
Write any extensions that may exist in a message.

@param msg A message that may contain extensions
@param gen The JSON generator
@param <EM> Type of message being serialized, containing extensions
@throws IOException any serialization error
Write any extensions that may exist in a message .