I have search some smilar question in stackoverflow. Referenced question is link .
I try to serialize a prometheus inner class called MetricFamilySamples in simple-client-0.9.0.jar. Package is io.prometheus.client.Collector$MetricFamilySamples. My serilize code is
Enumeration<Collector.MetricFamilySamples> metricFamilySamplesEnumeration = CollectorRegistry.defaultRegistry
.filteredMetricFamilySamples(metricQueryDTO.getParsedQueryStrSet());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
return objectMapper.writeValueAsString(metricFamilySamplesEnumeration));
I check the class and ensure the field is public. However, I got the following exception:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.lang.Object and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: io.prometheus.client.CollectorRegistry$MetricFamilySamplesEnumeration["collectorIter"]->java.util.HashMap$KeyIterator["current"]->java.util.HashMap$Node["com.clougence.cloudcanal.sidecar.component.collect.WorkerStatCollector@6274670b"])
The WorkerStatCollector is a implemented collector extend prometheus Collector. How can I serialize the class with jackson? I use another json serialize tool called fastjson and it can give the result like following picture(part of the result of fastjson serilization).