public class LayoutGadgetJSONWriter implements MessageBodyWriter<LayoutGadget> {
private String jsonRep = null;
public long getSize(LayoutGadget layoutGadget, Class<?> type,
Type genericType, Annotation[] annotations, MediaType mediaType) {
LayoutGadgetJSONSerializer serializer = new LayoutGadgetJSONSerializer();
try {
if (jsonRep == null)
jsonRep = serializer.convertToString(layoutGadget);
return jsonRep.getBytes("utf-8").length;
} catch(Exception ex) {
return -1;
}
}