/*
These custom serialization methods were added because commons config does not support
serialization.
176509
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    save(baos);

    byte[] data = baos.toByteArray();

    out.writeInt(data.length);
    out.write(data);
  }
1227699
private final void serializeObjectNoSCO(Object v, ZooFieldDef def) {
        // Write class/null info
        if (v == null) {
            writeClassInfo(null, null);
            out.skipWrite(def.getLength()-1);
            if (def.isString()) {
            	scos.add(null);
                return;
            }
            return;
        }
        
        //Persistent capable objects do not need to be serialized here.
        //If they should be serialized, then it will happen in serializeFields()
        Class<? extends Object> cls = v.getClass();
        writeClassInfo(cls, v);

        if (isPersistentCapable(cls)) {
            serializeOid((ZooPC) v);
            return;
        } else if (String.class == cls) {
        	scos.add(v);
        	String s = (String)v; 
        	out.writeLong(BitTools.toSortableLong(s));
            return;
        } else if (Date.class == cls) {
            out.writeLong(((Date) v).getTime());
            return;
        } else if (GenericObject.class.isAssignableFrom(cls)) {
        	serializeOid((GenericObject)v);
        	return;
        } else if (GOProxy.class.isAssignableFrom(cls)) {
        	serializeOid(((GOProxy)v).getGenericObject());
        	return;
        }
        
        throw new IllegalArgumentException("Illegal class: " + cls + " from " + def);
    }
250909
private String _serializeMap(Map map, Set<Object> done) throws ConverterException {
	StringBuilder sb = new StringBuilder(goIn() + "<struct>");

	Iterator it = map.keySet().iterator();

	deep++;
	while (it.hasNext()) {
	    Object key = it.next();
	    sb.append(goIn() + "<var name=" + del + XMLUtil.escapeXMLString(key.toString()) + del + ">");
	    sb.append(_serialize(map.get(key), done));
	    sb.append(goIn() + "</var>");
	}
	deep--;

	sb.append(goIn() + "</struct>");
	return sb.toString();
    }
228528
@SuppressWarnings("rawtypes")
		public void setObjectSerialization(Class<? extends Serialization> serialization) {
			if(type != Type.OBJECT) {
				throw new PangoolRuntimeException("Can't set custom serialization for type " + type);
			}
			if(serializationClass != null) {
				throw new PangoolRuntimeException("Serialization already set :" + serializationClass);
			}
			serializationClass = serialization;
		}
68565
@Deprecated
    @Override
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void serializeObject(JsonWriteGenericRecord record, String fieldName, String typeName, Object obj) {
        try {
            if (obj == null) {
                record.getGenerator().writeObjectField(fieldName, null);
                return;
            }
            if (isPrimitive(obj.getClass())) {
                serializePrimitive(record, fieldName, obj);
                return;
            }
            record.getGenerator().writeFieldName(fieldName);
            record.getGenerator().writeStartObject();

            NFTypeSerializer fieldSerializer = getSerializer(typeName);
            JsonWriteGenericRecord fieldRecord = new JsonWriteGenericRecord(record.getGenerator());
            fieldSerializer.serialize(obj, fieldRecord);
            record.getGenerator().writeEndObject();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
1123456
@Override
  public JsonElement serialize(ExpandableField<?> src, Type typeOfSrc,
      JsonSerializationContext context) {
    if (src.isExpanded()) {
      return context.serialize(src.getExpanded());
    } else if (src.getId() != null) {
      return new JsonPrimitive(src.getId());
    } else {
      return null;
    }
  }
843118
@Override
    public String serialize(Map<String, String> map) {

        try {

            // the format is based on the properties output format
            Properties props = new Properties();
            props.putAll(map);
            Writer writer = new StringWriter();
            props.store(writer, null);

            // we need a list of strings so we can further process the format
            List<String> lines = new ArrayList<String>();
            for (String line : writer.toString().split("\r?\n")) {
                // comments and empty lines are skipped
                if (!line.trim().isEmpty() && !line.trim().startsWith("#")) {
                    lines.add(line.trim());
                }
            }

            // sort by key so create a canonical format
            Collections.sort(lines);

            // build the output string
            StringBuilder builder = new StringBuilder();
            for (String line : lines) {

                if (multiline) {
                    if (builder.length() > 0) {
                        builder.append(lineSeparator);
                    }
                    builder.append(line);
                }
                else {
                    if (builder.length() > 0) {
                        builder.append("&");
                    }
                    builder.append(line.replace("&", "\\u0026"));
                }

            }
            return builder.toString();

        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

    }
961009
public void addDefaultSerializer (Class type, Serializer serializer) {
		if (type == null) throw new IllegalArgumentException("type cannot be null.");
		if (serializer == null) throw new IllegalArgumentException("serializer cannot be null.");
		insertDefaultSerializer(type, new SingletonSerializerFactory(serializer));
	}
595114
public void addDefaultKryoSerializer(Class<?> type, Class<? extends Serializer<?>> serializerClass) {
		config.addDefaultKryoSerializer(type, serializerClass);
	}
1178271
public String serialize(String name, Configuration configuration) {
      try {
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         serialize(os, name, configuration);
         return os.toString("UTF-8");
      } catch (Exception e) {
         throw new CacheConfigurationException(e);
      }
   }
529823
static public String serialize(CFEndPoint point) throws NotSerializableException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "serialize");
        }
        if (null == point) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Null CFEndPoint input for serialization");
            }
            throw new NotSerializableException("Null input");
        }
        // start the end point with name/host/port
        StringBuilder buffer = new StringBuilder(512);
        buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Serializing endpoint: " + point.getName());
        }
        buffer.append("<cfendpoint name=\"");
        buffer.append(point.getName());
        buffer.append("\" host=\"");
        buffer.append(point.getAddress().getCanonicalHostName());
        buffer.append("\" port=\"");
        buffer.append(point.getPort());
        buffer.append("\" local=\"");
        buffer.append(point.isLocal());
        buffer.append("\" ssl=\"");
        buffer.append(point.isSSLEnabled());
        buffer.append("\">\n");
        // loop through each channel in the list
        int i = 0;
        for (OutboundChannelDefinition def : point.getOutboundChannelDefs()) {
            buffer = serializeChannel(buffer, def, i++);
        }
        buffer.append("</cfendpoint>");
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Serialized string: \n" + buffer.toString());
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "serialize");
        }
        return buffer.toString();
    }
635404
public static JsonObject serialize(InstanceContext context) {
    return serialize(context.uri(), context.component().network());
  }
675258
private void _serializeComponent(Component c, StringBuilder sb, Set<Object> done) throws ConverterException {

	ComponentSpecificAccess cw = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, c);

	sb.append(goIn());
	try {
	    sb.append("evaluateComponent(").append(QUOTE_CHR).append(c.getAbsName()).append(QUOTE_CHR).append(',').append(QUOTE_CHR).append(ComponentUtil.md5(c)).append(QUOTE_CHR)
		    .append(",{");
	}
	catch (Exception e) {
	    throw toConverterException(e);
	}

	boolean doIt = false;
	Object member;
	{

	    Iterator<Entry<Key, Object>> it = cw.entryIterator();
	    deep++;
	    Entry<Key, Object> e;
	    while (it.hasNext()) {
		e = it.next();
		member = e.getValue();
		if (member instanceof UDF) continue;
		if (doIt) sb.append(',');
		doIt = true;
		sb.append(QUOTE_CHR);
		sb.append(escape(e.getKey().getString()));
		sb.append(QUOTE_CHR);
		sb.append(':');
		_serialize(member, sb, done);
	    }
	    sb.append("}");
	    deep--;
	}
	{
	    boolean isPeristent = c.isPersistent();

	    ComponentScope scope = c.getComponentScope();
	    Iterator<Entry<Key, Object>> it = scope.entryIterator();
	    sb.append(",{");
	    deep++;
	    doIt = false;
	    Property p;
	    Boolean remotingFetch;
	    Struct props = ignoreRemotingFetch ? null : ComponentUtil.getPropertiesAsStruct(c, false);
	    Entry<Key, Object> e;
	    Key k;
	    while (it.hasNext()) {
		e = it.next();
		k = e.getKey();
		// String key=Caster.toString(it.next(),"");
		if (KeyConstants._THIS.equalsIgnoreCase(k)) continue;
		if (!ignoreRemotingFetch) {
		    p = (Property) props.get(k, null);
		    if (p != null) {
			remotingFetch = Caster.toBoolean(p.getDynamicAttributes().get(REMOTING_FETCH, null), null);
			if (remotingFetch == null) {
			    if (isPeristent && ORMUtil.isRelated(p)) continue;
			}
			else if (!remotingFetch.booleanValue()) continue;
		    }
		}

		member = e.getValue();
		if (member instanceof UDF) continue;
		if (doIt) sb.append(',');
		doIt = true;
		sb.append(QUOTE_CHR);
		sb.append(escape(k.getString()));
		sb.append(QUOTE_CHR);
		sb.append(':');
		_serialize(member, sb, done);
	    }
	    sb.append("}");
	    deep--;
	}

	sb.append(")");
	// sb.append("");
	// throw new ConverterException("can't serialize a component "+component.getDisplayName());
    }
308524
static void serialize(DataOutput out, Serializers serializers)
      throws IOException {
    StringBuilder msg = new StringBuilder(String.format("Serialize %d serializer classes:", serializers.serializers.values().size()));
    int size = serializers.serializers.values().size();

    out.writeInt(size);
    if (size > 0) {
      for (SerializerWrapper sw : serializers.serializers.values()) {
        int index = sw.index;
        String name = sw.serializer.getClass().getName();

        out.writeInt(index);
        out.writeUTF(name);

        msg.append(String.format("%n  (%d) %s", index, name));
      }
      LOGGER.info(msg.toString());
    }
  }
317345
protected void serializeModifiers(QueryMetadata metadata, SQLSerializer context) {
        QueryModifiers mod = metadata.getModifiers();
        if (mod.getLimit() != null) {
            context.handle(limitTemplate, mod.getLimit());
        } else if (limitRequired) {
            context.handle(limitTemplate, maxLimit);
        }
        if (mod.getOffset() != null) {
            context.handle(offsetTemplate, mod.getOffset());
        }
    }
986368
Map<String, Object> serialize() {

		final Map<String, Object> map = new TreeMap<>();

		for (final StructrTypeDefinition type : typeDefinitions) {

			map.put(type.getName(), type.serialize());
		}

		return map;
	}
62800
public static String serialize(Method method, Object data) throws SerializationException {

        String result = RPC.encodeResponseForSuccess(method, data, CmsPrefetchSerializationPolicy.instance());
        result = CmsEncoder.escapeXml(result, true);
        return result;
    }