All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mikerusoft.jsonable.transform.SetTransformer Maven / Gradle / Ivy

There is a newer version: 1.2.13
Show newest version
package com.mikerusoft.jsonable.transform;

import com.mikerusoft.jsonable.utils.Outputter;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;

/**
 * Transforms Set into Json array
 */
public class SetTransformer  extends TransformerImpl {

    @Override
    public boolean match(Object o) {
        return matchClass(o.getClass());
    }

    @Override
    public boolean matchClass(Class clazz) {
        return Set.class.isAssignableFrom(clazz);
    }

    @Override
    public void transform(Object o, Outputter out, String... groups) throws IOException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Set l = (Set)o;
        out.write("[");
        int i = 0;
        for (Object p : l) {
            TransformerFactory.get(p).transform(p, out, groups);
            if (i != l.size() - 1)
                out.write(",");
            i++;
        }
        out.write("]");
    }

    @Override
    public int matchPriority() {
        return Transformer.HIGH_PRIORITY + 1;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy