use of org.osgi.util.converter.TargetRule in project felix by apache.
the class TypeConverter method getConverter.
public static Converter getConverter() {
return Converters.standardConverter().newConverterBuilder().rule(new TargetRule() {
@Override
public Type getTargetType() {
return String.class;
}
@Override
public ConverterFunction getFunction() {
return new ConverterFunction() {
@Override
public Object apply(final Object obj, final Type targetType) throws Exception {
if (obj instanceof Map || obj instanceof List) {
final JsonStructure json = JSONUtil.build(obj);
final StringWriter w = new StringWriter();
Json.createWriter(w).write(json);
return w.toString();
}
return CANNOT_HANDLE;
}
};
}
}).build();
}
Aggregations