package com.alterdekim.game.xml;

import com.alterdekim.game.component.game.avatar.BodyPartType;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class BodyPartTypeSerializer extends JsonSerializer<Object> {
    @Override
    public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeNumber(BodyPartTypeSerializer.parse(o));
    }

    public static Integer parse(Object o) {
        return o instanceof String ? (BodyPartType.valueOf((String) o)).getValue() : ((Number) o).intValue();
    }
}
