package com.bocloud.ims.entity.util;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class ObjectSerializer extends JsonSerializer<Object> {
	public ObjectSerializer() {
	}

	@Override
	public void serialize(Object object, JsonGenerator jgen, SerializerProvider provider) throws IOException {
		String value = object.toString();
		if (value.startsWith("{")) {
			object = JSONObject.parseObject(value.toString());
		} else if (value.startsWith("[")) {
			object = JSONObject.parseArray(value.toString());
		}
		jgen.writeObject(object);
	}
}