com.mikerusoft.jsonable.transform.SetTransformer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsonable Show documentation
Show all versions of jsonable Show documentation
Small library to convert Java POJO to and from JSON
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