/*
(non-Javadoc)

@see com.google.gson.JsonSerializer#serialize(java.lang.Object,
java.lang.reflect.Type, com.google.gson.JsonSerializationContext)
495393
public JsonElement serialize(Button src, Type typeOfSrc,
			JsonSerializationContext context) {
		ButtonType buttonType = src.getType();
		Class<?> buttonClass = getButtonClass(buttonType);
		return context.serialize(src, buttonClass);
	}
566737
@SneakyThrows
    public static void serialize(final Serializable object, final OutputStream outputStream) {
        try (val out = new ObjectOutputStream(outputStream)) {
            out.writeObject(object);
        }
    }
606889
@Override
	protected void serializeTo(RawDataBuffer out)
    {
    	super.serializeTo(out);
        out.writeInt(browserId.asInt());
    }
266953
@Override
	protected void serializeTo(RawDataBuffer out)
    {
        super.serializeTo(out);
    	if (message != null)
        {
            out.writeBoolean(true);
            MessageSerializer.serializeTo(message, out);
        }
        else
            out.writeBoolean(false);
    }
1136040
@SuppressWarnings("unchecked")
    @Override
    public final <T> T deserialize(byte[] content, Type type) throws SerializerException {
        if (byte[].class.equals(type)) {
            return (T) content;
        }
        throw new SerializerException("Unable to deserialize to type '" + type + "'");
    }
721175
@Override
  public JsonElement serialize(CMAField field, Type type, JsonSerializationContext context) {
    JsonObject json = new JsonObject();

    add(json, ATTR_ID, field.getId());
    add(json, ATTR_NAME, field.getName());
    add(json, ATTR_TYPE, field.getType());
    add(json, ATTR_LINK_TYPE, field.getLinkType());
    add(json, ATTR_REQUIRED, field.isRequired());
    add(json, ATTR_DISABLED, field.isDisabled());
    add(json, ATTR_OMITTED, field.isOmitted());
    add(json, ATTR_LOCALIZED, field.isLocalized());

    List<Map<String, Object>> validations = field.getValidations();
    if (validations != null) {
      json.add(ATTR_VALIDATIONS, context.serialize(validations,
          new TypeToken<List<Map<String, Object>>>() {
          }
          .getType()));
    }

    Map<String, Object> arrayItems = field.getArrayItems();
    if (arrayItems != null) {
      json.add(ATTR_ARRAY_ITEMS, context.serialize(arrayItems, Map.class));
    }

    return json;
  }
277834
@Override
  public <T> ByteBuffer serialize(final Serializer<T> serializer, final T value)
    throws IOException {
    try (final BytesSerialWriter writer = writeBytes()) {
      serializer.serialize(writer, value);
      return writer.toByteBuffer();
    }
  }
961891
@Override
    public void serialize(PrincipalUser value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        jgen.writeStartObject();
        jgen.writeStringField("id", value.getId().toString());
        jgen.writeStringField("createdBy", value.getCreatedBy() == null ? null : value.getCreatedBy().getUserName());
        jgen.writeNumberField("createdDate", value.getCreatedDate() == null ? null : value.getCreatedDate().getTime());
        jgen.writeStringField("modifiedBy", value.getModifiedBy() == null ? null : value.getModifiedBy().getUserName());
        jgen.writeNumberField("modifiedDate", value.getModifiedDate() == null ? null : value.getModifiedDate().getTime());
        jgen.writeStringField("userName", value.getUserName());
        jgen.writeStringField("email", value.getEmail());
        jgen.writeBooleanField("privileged", value.isPrivileged());
        jgen.writeEndObject();
    }
735772
@Override
    protected byte[] serialize(Object o) {
        ClassLoaderRegisteringObjectInputStream.register(o.getClass());
        return super.serialize(o);
    }
769946
public static JsonValue serializeAsJson(Object o) throws IOException {
        try {
            return findFieldsToSerialize(o).mainObject;
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
859101
@Override
	public void serializeCollection(BinderContext context, SerializerWrapper serializerWrapper, Collection<E> collection) throws Exception {
		switch (context.getSupportedFormat()) {
		case XML: {
			throw (new KriptonRuntimeException(context.getSupportedFormat() + " context does not support direct collection persistance"));
		}
		default: {
			JacksonWrapperSerializer wrapper = (JacksonWrapperSerializer) serializerWrapper;
			JsonGenerator jacksonGenerator=wrapper.jacksonGenerator;

			try {
				jacksonGenerator.writeStartArray();
				if (context.getSupportedFormat().onlyText)
					for (E object : collection) {
						serializeOnJacksonAsString(object, jacksonGenerator);
					}
				else
					for (E object : collection) {
						serializeOnJackson(object, jacksonGenerator);
					}
				jacksonGenerator.writeEndArray();
			} catch (IOException e) {
				e.printStackTrace();
				throw (new KriptonRuntimeException(e));
			}
		}
			break;
		}
	}
1134946
public JsonElement serialize(Calendar src, Type typeOfSrc,
			JsonSerializationContext context) {
		int year = src.get(Calendar.YEAR);
		String month = this.formatter.format(Double.valueOf(src
				.get(Calendar.MONTH) + 1));
		String day = this.formatter.format(Double.valueOf(src
				.get(Calendar.DAY_OF_MONTH)));
		String hour = this.formatter.format(Double.valueOf(src
				.get(Calendar.HOUR_OF_DAY)));
		String minute = this.formatter.format(Double.valueOf(src
				.get(Calendar.MINUTE)));
		String formattedDate = year + "-" + month + "-" + day + "T" + hour
				+ ":" + minute;

		return context.serialize(formattedDate);
	}
650180
public static void writeJson(@javax.annotation.Nonnull final OutputStream out, final Object obj) throws IOException {
    final ObjectMapper mapper = new ObjectMapper().enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL)
      .enable(SerializationFeature.INDENT_OUTPUT);
    @javax.annotation.Nonnull final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    mapper.writeValue(buffer, obj);
    out.write(buffer.toByteArray());
  }
778007
@Override
    public String serialize(final FedoraEvent evt) {
        try {
            return MAPPER.writeValueAsString(from(evt));
        } catch (final JsonProcessingException ex) {
            LOGGER.error("Error processing JSON: {}", ex.getMessage());
            return null;
        }
    }
1226389
public final <T> SerializerJson<T> serializer(Type type)
  {
    SerializerJson<T> ser = (SerializerJson<T>) _serTypeMap.get(type);
    
    if (ser == null) {
      TypeRef typeRef = TypeRef.of(type);
      Class<T> rawClass = (Class<T>) typeRef.rawClass();
      
      ser = serializer(rawClass).withType(typeRef, this);
      
      _serTypeMap.putIfAbsent(type, ser);
      
      ser = (SerializerJson<T>) _serTypeMap.get(type);
    }
    
    return ser;
  }
1033405
public static Object serializeAndDeserialize(Object o) throws IOException,
			ClassNotFoundException {
		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		ObjectOutputStream out = new ObjectOutputStream(bytes);
		try {
			out.writeObject(o);
		} finally {
			out.close();
		}

		ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
				bytes.toByteArray()));
		try {
			Object result = in.readObject();
			return result;
		} finally {
			in.close();
		}
	}
1242052
protected void serialize(BinderContext context, E object, SerializerWrapper serializerWrapper, boolean writeStartAndEnd) throws Exception {

		switch (context.getSupportedFormat()) {
		case XML:
			try {
				XmlWrapperSerializer wrapper = ((XmlWrapperSerializer) serializerWrapper);
				XMLSerializer xmlSerializer=wrapper.xmlSerializer;

				if (writeStartAndEnd) {
					xmlSerializer.writeStartDocument();
				}
				serializeOnXml(object, xmlSerializer, 0);

				if (writeStartAndEnd) {
					xmlSerializer.writeEndDocument();
				}
			} catch (Exception e) {
				e.printStackTrace();
				throw (new KriptonRuntimeException(e));
			}
			break;
		default:
			if (context.getSupportedFormat().onlyText)
				serializeOnJacksonAsString(object, ((JacksonWrapperSerializer) serializerWrapper).jacksonGenerator);
			else
				serializeOnJackson(object, ((JacksonWrapperSerializer) serializerWrapper).jacksonGenerator);
			break;
		}
	}